Improve demo user check to not rely on primary key
This commit is contained in:
parent
57e7d3ba0a
commit
0ede36c76d
|
@ -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();
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue