dimanche 20 septembre 2015

Laravel 5.1 Call to undefined method Illuminate\Database\Query\Builder::isSuperAdmin()

So I'm trying to understand user authorization in Laravel 5.1.

Based on the docs I've set up the AuthServiceProvider boot method as follows:

public function boot(GateContract $gate)
{
    parent::registerPolicies($gate);

    $gate->define('view-dashboard', function ($user, $post) {        
        return $user->id === $post->user_id;
    });

    $gate->before(function ($user, $ability) {
        if($user->isSuperAdmin()) {
            return true;
        }
    });   
}

In my controller I have:

    if (Gate::denies('view-dashboard')) {
        return view('auth.login');
    }

    return view('admin.home');

When I'm not logged in I get the auth.login view. However, once I log in I get the following error:

BadMethodCallException in Builder.php line 2025: Call to undefined method Illuminate\Database\Query\Builder::isSuperAdmin()

First, since I took those lines straight out of the docs, I'm not sure why I would get that error. Any ideas?

Second, the docs don't seem to explain how to go about designating a given user as a Super Admin, or how to give a user specific abilities (such as the "view-dashboard" ability in my example). How do I do this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire