Support the ongoing development of Laravel.io →
Eloquent Architecture
Last updated 2 years ago.
0

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.

0

Responsibility seems the same to me. They both filter the results. They both filter with almost the same code.

0

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.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

hkan hkan Joined 15 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.