Итак, я пытаюсь создать глобальную область в laravel 5.1, но просто продолжаю получать следующую ошибку: Trait 'Eloquent\Scopes\DependentTypeTrait' not found
.Laravel 5.1 выпуск, реализующий глобальную область
Вот мой код:
App \ Models \ красноречивый \ Областей \ 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);
}
}
App \ Models \ красноречивый \ Прицелы \ DependentTypeScope.php:
<?php namespace App\Models\Eloquent\Scopes;
use Illuminate\Database\Eloquent\ScopeInterface;
use Illuminate\Database\Eloquent\Builder;
class DependentTypeScope implements ScopeInterface
{
public function apply(Builder $builder)
{
$builder->where('vip_type_id', 2);
}
public function remove(Builder $builder)
{
$query = $builder->getQuery();
// here you remove the where close to allow developer load
// without your global scope condition
foreach ((array) $query->wheres as $key => $where) {
if ($where['column'] == 'vip_type_id') {
unset($query->wheres[$key]);
$query->wheres = array_values($query->wheres);
}
}
}
}
Приложение \ Модели \ Dependent.php:
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Eloquent\Scopes\DependentTypeTrait;
class Dependent extends Model
{
use DependentTypeTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = '<my table name>';
/**
* The actual primary key for the model.
*
* @var string
*/
protected $primaryKey = '<my primary key>';
}
Я чувствую, что у меня правильное пространство имен, но оно все еще говорит, что он не может найти атрибут ... любые идеи?
Вы правы! Я предполагал, что поскольку пространство имен на модели было App \ Namespace, мне не нужно было добавлять это в использование ... –