Separation of responsibility.
Local scope (on the model/trait) would require you to include the SoftDeletingScope
and use its remove
method on the query, that's why the query has extension instead.
Responsibility seems the same to me. They both filter the results. They both filter with almost the same code.
You're talking about what the methods do, not what the class is responsible for.
Yes, you could do exactly the same with such scopes in the trait:
public function scopeWithTrashed($q)
{
$scope = new SoftDeletingScope;
$scope->remove($q);
}
public function scopeOnlyTrashed($q)
{
$scope = new SoftDeletingScope;
$scope->remove($q);
$q->getQuery()->whereNotNull($q->getModel()->getQualifiedDeletedAtColumn());
}
but that's not the responsibility of the trait. It's the scope that's responsible for this, while trait is just a sugar so you can simply add use SoftDeletingTrait
to your model and that's all.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community