Improve demo user check to not rely on primary key

This commit is contained in:
Jonathan Reinink 2019-12-18 17:33:46 -05:00
parent 57e7d3ba0a
commit 0ede36c76d
2 changed files with 7 additions and 2 deletions

View File

@ -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();

View File

@ -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');