【问题标题】:Laravel 5.2.2 and Entrust error call to undefined methodLaravel 5.2.2 和 Entrust 错误调用未定义的方法
【发布时间】:2016-03-02 04:40:28
【问题描述】:

当我使用最新的 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

我也已经生成了需要的模型

我错过了什么吗?

【问题讨论】:

    标签: laravel entrust


    【解决方案1】:

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

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

    CACHE_DRIVER=array
    

    别忘了跑

    php artisan config:cache
    

    【讨论】:

    【解决方案2】:

    看来所有步骤都正确,我只需要用php artisan config:cache清除缓存

    如果您遇到如下错误

    BadMethodCallException in vendor\laravel\framework\src\Illuminate\Cache\Repository.php line 380:
    This cache store does not support tagging.
    

    你需要在.env中把这一行改成数组

    CACHE_DRIVER=array
    

    【讨论】:

    • 我有同样的错误。我尝试在 .env 文件和配置/缓存文件中更改 CACHE_DRIVER=array 'default' => env('CACHE_DRIVER', 'array') 但我遇到了新错误 [Symfony\Component\Debug\Exception\FatalErrorException] Class 'App\Permission' not found 你能帮帮我吗?跨度>
    【解决方案3】:

    试试这个:

    打开你的 laravel 环境文件,将 CACHE_DRIVER=file 改为 CACHE_DRIVER=array 并保存。

    现在试试你的 CLI 命令。

    【讨论】:

      【解决方案4】:

      Laravel 驱动程序不支持标记。要解决此问题,请转到您的 .env 文件并更改

      Cache_driver=file
      

      Cache_driver=array
      

      然后运行

      php artisan config:cache
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-21
        • 2015-04-17
        • 2018-08-14
        • 2018-07-03
        相关资源
        最近更新 更多