当 Laravel 从 5.1 升级到 5.2 时,未发现特性“Illuminate\Foundation\Bus\DispatchesCommands”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34589987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:58:10  来源:igfitidea点击:

Trait 'Illuminate\Foundation\Bus\DispatchesCommands' not found error while laravel upgrading to 5.2 from 5.1?

phplaravelupgradelaravel-5.2

提问by gsk

When I am trying to upgrade from laravel 5.1 to 5.2, I am getting following error

当我尝试从 laravel 5.1 升级到 5.2 时,出现以下错误

Trait 'Illuminate\Foundation\Bus\DispatchesCommands' not found in D:\xampp\htdocs\Invoice\web\bootstrap\cache\compiled.php

My controller class is,

我的控制器类是,

    namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

abstract class Controller extends BaseController {

    use DispatchesCommands,
        ValidatesRequests;

    function __construct() {
        $this->middleware('auth');
    }

}

}

In laravel documentation, they saying it deprecated

在laravel文档中,他们说它已弃用

So how can I fix this?

那么我该如何解决这个问题?

回答by Bogdan

Deprecated doesn't mean that it's been removed, just that it will be at some point. They do mention a fix for it in the documentation:

弃用并不意味着它已被删除,只是它会在某个时候被删除。他们确实在文档中提到了一个修复程序:

The Illuminate\Foundation\Bus\DispatchesCommandstrait has been deprecated and renamed to Illuminate\Foundation\Bus\DispatchesJobs.

Illuminate\Foundation\Bus\DispatchesCommands特性已被弃用并重命名为Illuminate\Foundation\Bus\DispatchesJobs.

So just replace this:

所以只需替换这个:

use Illuminate\Foundation\Bus\DispatchesCommands;

With this:

有了这个:

use Illuminate\Foundation\Bus\DispatchesJobs;

There should not be any worries about this breaking in the future as the DispatchesCommandstrait was including the DispatchesJobstrait which was also present in another form in 5.1.

将来不必担心这种破坏,因为该DispatchesCommands特性包括DispatchesJobs在 5.1 中也以另一种形式存在的特性。