Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blade macro for both canImpersonate and canBeImpersonated #152

Open
howdu opened this issue Feb 11, 2022 · 0 comments
Open

Blade macro for both canImpersonate and canBeImpersonated #152

howdu opened this issue Feb 11, 2022 · 0 comments

Comments

@howdu
Copy link

howdu commented Feb 11, 2022

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();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants