Improve demo user check to not rely on primary key
This commit is contained in:
parent
57e7d3ba0a
commit
0ede36c76d
2 changed files with 7 additions and 2 deletions
|
@ -79,8 +79,8 @@ class UsersController extends Controller
|
||||||
|
|
||||||
public function update(User $user)
|
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.');
|
return Redirect::route('users.edit', $user)->with('error', 'Updating the demo user is not allowed.');
|
||||||
|
if (App::environment('demo') && $user->isDemoUser()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Request::validate([
|
Request::validate([
|
||||||
|
@ -107,8 +107,8 @@ class UsersController extends Controller
|
||||||
|
|
||||||
public function destroy(User $user)
|
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.');
|
return Redirect::route('users.edit', $user)->with('error', 'Deleting the demo user is not allowed.');
|
||||||
|
if (App::environment('demo') && $user->isDemoUser()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->delete();
|
$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)
|
public function scopeOrderByName($query)
|
||||||
{
|
{
|
||||||
$query->orderBy('last_name')->orderBy('first_name');
|
$query->orderBy('last_name')->orderBy('first_name');
|
||||||
|
|
Loading…
Add table
Reference in a new issue