Laravel 5.2.2 和 Entrust 错误调用未定义方法

标签 laravel entrust

当我使用最新的 Laravel 5.2.2 和 Entrust ("zizaco/entrust": "5.2.x-dev") 时,我遇到了这个错误,不知道如何解决这个问题:

Call to undefined method Zizaco\Entrust\EntrustServiceProvider::hasRole()
我在 HomeController.php 上测试了这段代码
use Entrust;

class HomeController extends Controller
{ 


    public function index()
    {
        if (Entrust::hasRole('admin')) {
            echo "string";
        }

        return view('home');
    }
}
这是我的 config/app.php 服务提供者
Zizaco\Entrust\EntrustServiceProvider::class
config/app.php 门面别名
'Entrust'   => Zizaco\Entrust\EntrustFacade::class
我也已经生成了所需的模型
enter image description here
enter image description here
enter image description here
我在这里错过了什么吗?

最佳答案

我有同样的问题,这是我为解决问题而采取的步骤

在您的 .env 文件中更改为缓存数组

CACHE_DRIVER=array

并且不要忘记运行
php artisan config:cache

关于Laravel 5.2.2 和 Entrust 错误调用未定义方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35738642/

相关文章:

Laravel 5 将字符串主键作为整数返回

mysql - 关联或保存关系仅在 Laravel 中可为空时才有效

php - Laravel 5.1 使用变量重定向

php - Laravel - 语法错误,文件意外结束

php - 在 laravel 中为资源的每个方法分配单独的中间件

php - 如何在 laravel 5.2 zizaco entrust :migration class name validation? 中修复

laravel - Eloquent 将属性转换为 Collections 的意外行为

php - Laravel 5 Entrust - 用户属于许多应用程序

php - 我如何在注册期间为用户分配角色? (委托(delegate))(Laravel 5.1)

laravel - Zizaco 委托(delegate)不会创建 entrust.php