Php Laravel 5.1实施全球范围的问题
因此,我试图在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
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"
}
},