Laravel-permission: on lumen 5.7 package requires facades

Created on 7 Dec 2018  路  6Comments  路  Source: spatie/laravel-permission

if i put service provider into app.php

$app->register(Spatie\Permission\PermissionServiceProvider::class);

i get an error: A facade root has not been set.
in previous versions, this was not necessary

in the lumen it is not recommended to use of facades
how can this be avoided?

thanx!

bug

Most helpful comment

From version 2.28.1 I get the following error in Lumen 5.7.6

BindingResolutionException
Unresolvable dependency resolving [Parameter #0 [ <required> $app ]] in class Illuminate\Cache\CacheManager

To resolve this error I have to add the following to bootstrap/app.php

$app->alias('cache', \Illuminate\Cache\CacheManager::class);

I don't know if this is an issue with laravel/lumen-framework, illuminate/cache or spatie/laravel-permission

All 6 comments

Apologies. We should fix that!

In the meantime you could use version 2.25.0 of the package.

The latest, version 2.28.1 should work properly as well.

From version 2.28.1 I get the following error in Lumen 5.7.6

BindingResolutionException
Unresolvable dependency resolving [Parameter #0 [ <required> $app ]] in class Illuminate\Cache\CacheManager

To resolve this error I have to add the following to bootstrap/app.php

$app->alias('cache', \Illuminate\Cache\CacheManager::class);

I don't know if this is an issue with laravel/lumen-framework, illuminate/cache or spatie/laravel-permission

From version 2.28.1 I get the following error in Lumen 5.7.6

BindingResolutionException
Unresolvable dependency resolving [Parameter #0 [ <required> $app ]] in class Illuminate\Cache\CacheManager

To resolve this error I have to add the following to bootstrap/app.php

$app->alias('cache', \Illuminate\Cache\CacheManager::class);

I don't know if this is an issue with laravel/lumen-framework, illuminate/cache or spatie/laravel-permission

Thank you very much!!

apparently this does not apply to this package, but it would be nice if the authors will cover this point in the documentation (it describes how to integrate the package in lumen)

I think it might be a problem with this package now using \Illuminate\Cache\CacheManager in PermissionRegistrar::__construct() and type-hinting...

https://github.com/spatie/laravel-permission/blob/7f308806ca051fca42685e4a97a282139a6a7982/src/PermissionRegistrar.php#L42-L56

If I change it to the following, it stops the error

    /**
     * PermissionRegistrar constructor.
     *
     * @param \Illuminate\Contracts\Auth\Access\Gate $gate
     */
    public function __construct(Gate $gate)
    {
        $this->gate = $gate;
        $this->permissionClass = config('permission.models.permission');
        $this->roleClass = config('permission.models.role');
        $this->cacheManager = app('cache');
        $this->initializeCache();
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

devingray picture devingray  路  3Comments

tripex picture tripex  路  3Comments

younus93 picture younus93  路  4Comments

dylangeorgeharbour picture dylangeorgeharbour  路  3Comments

wreighsantos picture wreighsantos  路  4Comments