Digging into Laravel SoftDeletes

Laravel SoftDeletes
public function apply(Builder $builder, Model $model)
{
$builder->whereNull($model->getQualifiedDeletedAtColumn());
}
const DELETED_AT = ‘your_column_name’;
protected function addWithTrashed(Builder $builder)
{
$builder->macro(‘withTrashed’, function (Builder $builder, $withTrashed = true) {
if (! $withTrashed) {
return $builder->withoutTrashed();
}
return $builder->withoutGlobalScope($this);
});
}
//This will call the Delete Method in Trait
Post::find(2)->delete()
//This will call the Delete Method in Scope.
Post::withoutTrashed()->delete()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store