404labfr / laravel-impersonate

Laravel Impersonate is a plugin that allows you to authenticate as your users.
https://marceau.casals.fr
1.95k stars 203 forks source link

Blade macro for both canImpersonate and canBeImpersonated #152

Open howdu opened 2 years ago

howdu commented 2 years ago

Is there a cleaner way of checking both?

@foreach($users as $user)
    @canImpersonate()
        @canBeImpersonated($user)
           <a href="{{ route('impersonate', $user->id) }}">Impersonate this user</a>
        @endCanBeImpersonated
    @endCanImpersonate
@endforeach

User model I only want super admin to be able to impersonate.

/**
     * Allow authenticate of another users
     * @return bool
     */
    public function canImpersonate()
    {
        return $this->isSuperAdmin();
    }

    /**
     * Allow authenticate of this user
     * @return bool
     */
    public function canBeImpersonated()
    {
        return !$this->isSuperAdmin();
    }