Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.1实施全球范围的问题_Php_Laravel_Scope - Fatal编程技术网

Php Laravel 5.1实施全球范围的问题

Php Laravel 5.1实施全球范围的问题,php,laravel,scope,Php,Laravel,Scope,因此,我试图在laravel 5.1中创建一个全局作用域,但一直没有找到以下错误Trait'Eloquent\Scopes\DependentTypeTrait' 这是我的密码: App\Models\Eloquent\Scopes\DependentTypeTrait.php: <?php namespace App\Models\Eloquent\Scopes; trait DependentTypeTrait { /** * Boot the Active Ev

因此,我试图在laravel 5.1中创建一个全局作用域,但一直没有找到以下错误
Trait'Eloquent\Scopes\DependentTypeTrait'

这是我的密码:

App\Models\Eloquent\Scopes\DependentTypeTrait.php:

<?php namespace App\Models\Eloquent\Scopes;

trait DependentTypeTrait {

    /**
     * Boot the Active Events trait for a model.
     *
     * @return void
     */
    public static function bootDependentTypeTrait()
    {
        static::addGlobalScope(new DependentTypeScope);
    }

}

我认为您在尝试导入您的
DependentTypeTrait
时,使用名称空间是错误的:

<?php namespace App\Models\Eloquent\Scopes;

trait DependentTypeTrait { //...
这些名称空间不匹配。请尝试以下方法:

use App\Models\Eloquent\Scopes\DependentTypeTrait;
或者,您可以修改
composer.json
以更改自动加载
雄辩
命名空间的方式:

"autoload": {
    "psr-4": {
        "Eloquent\\": "app/Models/Eloquent"
    }
},
别忘了卸载自动加载器:
$composer dump autoload


虽然特别是因为你使用的是在拉雷维尔随处可见的名字
雄辩
,我自己也不会走这条路,即使你可以省去一些打字。Laravel本身使用名称空间
illumb\Database\elount
,因此您目前可能不会遇到冲突,但如果Taylor改变了事情,或者您使用第三方库对其进行踩踏,则可能存在这种情况。

您是正确的!我假设,由于模型上的名称空间是App\namespace,因此我不必在使用中添加此名称空间。。。。
use Eloquent\Scopes\DependentTypeTrait;
use App\Models\Eloquent\Scopes\DependentTypeTrait;
"autoload": {
    "psr-4": {
        "Eloquent\\": "app/Models/Eloquent"
    }
},