-
app/Services/UserService.php
Open in GitHubuse Illuminate\Support\Facades\Hash; class UserService { public function updateUserEmail(array $data, object $user) { $user->email = $data['email']; $user->save(); return $user; } public function updateUserPassword(array $data, object $user) { $user->password = Hash::make($data['new-password']); $user->save(); return $user; } }
-
app/Http/Controllers/Dashboard/User/UserController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Requests\UpdateUserEmail; use App\Models\User; use App\Services\UserService; class UserController extends Controller { public function __construct(protected UserService $userSrvc) {} public function update(UpdateUserEmail $request, User $user) { $data = $request->only('email'); $this->userSrvc->updateUserEmail($data, $user); return redirect()->back() ->withFlashSuccess(__('Profile updated.')); } }
-
app/Http/Controllers/Dashboard/User/ChangePasswordController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Requests\UpdateUserPassword; use App\Models\User; use App\Services\UserService; class ChangePasswordController extends Controller { public function __construct(protected UserService $userSrvc) { // } public function update(UpdateUserPassword $request, User $user) { $data = $request->only('new-password'); $this->userSrvc->updateUserPassword($data, $user); return redirect()->back() ->withFlashSuccess(__('Password changed successfully !')); } }