diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 53b746b..bcb1d3b 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -79,8 +79,8 @@ class UsersController extends Controller public function update(User $user) { - if (App::environment('demo') && $user->id === 1) { return Redirect::route('users.edit', $user)->with('error', 'Updating the demo user is not allowed.'); + if (App::environment('demo') && $user->isDemoUser()) { } Request::validate([ @@ -107,8 +107,8 @@ class UsersController extends Controller public function destroy(User $user) { - if (App::environment('demo') && $user->id === 1) { return Redirect::route('users.edit', $user)->with('error', 'Deleting the demo user is not allowed.'); + if (App::environment('demo') && $user->isDemoUser()) { } $user->delete(); diff --git a/app/User.php b/app/User.php index 81664c6..250f969 100644 --- a/app/User.php +++ b/app/User.php @@ -42,6 +42,11 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac } } + public function isDemoUser() + { + return $user->email === 'johndoe@example.com'; + } + public function scopeOrderByName($query) { $query->orderBy('last_name')->orderBy('first_name');