diff --git a/app/Http/Controllers/Api/V1/UserController.php b/app/Http/Controllers/Api/V1/UserController.php new file mode 100644 index 0000000..32fd49f --- /dev/null +++ b/app/Http/Controllers/Api/V1/UserController.php @@ -0,0 +1,48 @@ +content = array(); + } + + public function updateProfile(Request $request) + { + $auth = Auth::user(); + $user = User::find($auth->id); + + if($user->update([ + 'name' => $request->input('name') && !empty($request->input('name')) + ? $request->input('name') + : $auth->name, + 'email' => $request->input('email') && !empty($request->input('email')) + ? $request->input('email') + : $auth->email, + 'password' => $request->input('password') && !empty($request->input('password')) + ? !Hash::check($request->input('old_password'), $user->password) + ? $user->password + : bcrypt($request->input('password')) + : $user->password, + ])) { + $this->content['data'] = User::with('company')->find($auth->id); + $this->content['status'] = 200; + return response()->json($this->content, $this->content['status'], [], JSON_NUMERIC_CHECK); + } + + $this->content['error'] = "Server Error"; + $this->content['status'] = 500; + + return response()->json($this->content, $this->content['status'], [], JSON_NUMERIC_CHECK); + } +} diff --git a/routes/api.php b/routes/api.php index c2ad1fa..18924b5 100644 --- a/routes/api.php +++ b/routes/api.php @@ -131,6 +131,17 @@ }); +// Users API +Route::group(['prefix' => 'users', 'namespace' => '\Api\V1'], function() +{ + Route::put('/profile', [ + 'as' => 'api.users.profile.update', + 'middleware' => 'auth:api', + 'uses' => 'UserController@updateProfile', + ]); +}); + + // Customers API Route::group(['prefix' => 'customers', 'namespace' => '\Api\V1'], function() {