【发布时间】:2019-01-03 07:21:25
【问题描述】:
根据这个问题:Is it possible to perform "future" soft delete in laravel? 它可以在 laravel 5.6 中使用吗?如果可以的话我在哪里可以创建特征
我尝试在 app\Traits\ 中创建 Traits,但是当我在模型中调用时它总是说 Trait 'App\Traits\MySoftDeletingTrait' not found
我在 app\Traits 中创建了 2 个文件 - MySoftDeletingScope.php
namespace App\Traits;
class MySoftDeletingScope extends Illuminate\Database\Eloquent\SoftDeletingScope {
public function apply(Builder $builder)
{
$model = $builder->getModel();
$builder->where($model->getQualifiedDeletedAtColumn(), '<=', Carbon::now());
$this->extend($builder);
}
}
the 2nd one MySoftDeleteingTrait.php
namespace App\Traits;
use Illuminate\Database\Eloquent\SoftDeletingTrait;
trait MySoftDeletingTrait {
public static function bootSoftDeletingTrait()
{
static::addGlobalScope(new MySoftDeletingScope);
}
}
在 Uer php 中我调用
使用 App\Traits\MySoftDeletingTrait; 使用 Notifiable、HasRoles、MySoftDeletingTrait;
【问题讨论】: