From d8c4ea1bcdb499eac13b8f7f61895e54c1baa35b Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 14 May 2018 17:12:59 +0800 Subject: [PATCH] added update role in update profile --- app/Http/Controllers/AuthController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 6ab2d0e..f8bbb25 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -6,6 +6,8 @@ use App\UserVerification; use App\PasswordResets; use JWTAuth; use Auth; +use App\Role; + use Aloha\Twilio\Twilio; use Tymon\JWTAuth\Exceptions\JWTException; use Validator, DB, Hash, Mail, Illuminate\Support\Facades\Password; @@ -118,13 +120,21 @@ class AuthController extends Controller if($validator->fails()) { return response()->json(['success'=> false, 'error'=> $validator->messages()]); } - + + + $name = $request->name; $password = $request->password; + $role = $request->role; - $user = Auth::user(); - $user->update(['name' => $name, 'password' => Hash::make($password)]); + // find role + $role = Role::where('name','=',$role)->first(); + $user = Auth::user(); + + // attach role to user + $user->attachRole($role); + $user->update(['name' => $name, 'password' => Hash::make($password)]); return response()->json(['success'=> true, 'message'=> 'Profile updated.']); }