Skip to content

Commit

Permalink
⬆️ Login as user
Browse files Browse the repository at this point in the history
  • Loading branch information
rxcod9 committed Apr 6, 2022
1 parent df9aefd commit ad1f69a
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 163 deletions.
18 changes: 18 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Lab404\Impersonate\Models\Impersonate;
use Laravel\Passport\HasApiTokens;

class User extends \TCG\Voyager\Models\User
{
use HasApiTokens;
use HasFactory;
use Notifiable;
use Impersonate;

/**
* The attributes that are mass assignable.
Expand Down Expand Up @@ -50,4 +52,20 @@ public function scopeGlobalSearch(Builder $query, $value): void
->orWhere('name', 'LIKE', '%' . $value . '%')
->orWhere('email', 'LIKE', '%' . $value . '%');
}

/**
* @return bool
*/
public function canImpersonate()
{
return $this->hasRole('admin');
}

/**
* @return bool
*/
public function canBeImpersonated()
{
return !$this->hasRole('admin');
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"joy/voyager-duplicate": "^1.0",
"joy/voyager-export": "^1.0",
"joy/voyager-import": "^1.0",
"joy/voyager-login-as-user": "^1.0",
"joy/voyager-login-as-user": "^1.2",
"joy/voyager-merge": "^1.0",
"joy/voyager-relations-table": "^1.0",
"joy/voyager-user-settings": "^1.0",
Expand Down Expand Up @@ -88,4 +88,4 @@
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": {}
}
}
Loading

0 comments on commit ad1f69a

Please sign in to comment.