Added Event Dispatcher To Account Controller's Method

This commit is contained in:
Devansh 2020-08-01 19:55:35 +05:30
parent f05b17aa99
commit afd2de92bd
1 changed files with 8 additions and 1 deletions

View File

@ -3,6 +3,7 @@
namespace Webkul\User\Http\Controllers;
use Hash;
use Illuminate\Support\Facades\Event;
class AccountController extends Controller
{
@ -26,7 +27,7 @@ class AccountController extends Controller
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\View\View
* @return \Illuminate\View\View
*/
public function edit()
{
@ -42,6 +43,7 @@ class AccountController extends Controller
*/
public function update()
{
$isPasswordChanged = false;
$user = auth()->guard('admin')->user();
$this->validate(request(), [
@ -62,11 +64,16 @@ class AccountController extends Controller
if (! $data['password']) {
unset($data['password']);
} else {
$isPasswordChanged = true;
$data['password'] = bcrypt($data['password']);
}
$user->update($data);
if ($isPasswordChanged) {
Event::dispatch('user.admin.update-password', $user);
}
session()->flash('success', trans('admin::app.users.users.account-save'));
return back();