According to this Question : Is it possible to perform "future" soft delete in laravel? Is it can use in laravel 5.6 ? and If It can Where can I create Traits
I try to create Traits in app\Traits\ but when I call in in models It always said Trait 'App\Traits\MySoftDeletingTrait' not found
I created 2 file in app\Traits - 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);
}
}
In Uer php I call
use App\Traits\MySoftDeletingTrait; use Notifiable, HasRoles, MySoftDeletingTrait;