samedi 2 mars 2019

Laravel - Only query model if table exists

So I have a boot() in my AuthServiceProvider that reads some Permissions from the database:

    foreach (Permission::all() as $perm) {
        Gate::define($perm->name, function ($id) use ($perm) {
            $user = config('user')::where('id', $id)->firstOrFail();
            return $user->hasPermission($perm->name);
        });
    }

Only problem is when I do migrate:fresh everything breaks (with an exception) because, well, the tables don't exist.

How can I tell the Permission model to only load data if the table exists?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire