Having trouble finding the way to use Query Scopes with Repositories. Is there a way?
Would like to use for basic scoping as in the example.
http://laravel.com/docs/eloquent#query-scopes
// Model based example from docs...
class User extends Eloquent {
public function scopePopular($query)
{
return $query->where('votes', '>', 100);
}
public function scopeWomen($query)
{
return $query->whereGender('W');
}
}
$users = User::popular()->women()->orderBy('created_at')->get();
Example using Repositories instead of Models?
What do you mean by Repositories instead of Models ?
class UserRepository{
public function getPopularWomen(){
return User::popular()->women()->orderBy('created_at')->get();
}
}
:)
That could be useful for testing (by injecting repositories in the controllers). But repositories are often associated with the data mapper design pattern, which has a different way of handling data than active record (Eloquent's design pattern). Take a look at Doctrine if you're interested in the data mapper pattern.
It's not difficult. I just do something like this: https://gist.github.com/thepsion5/eb0af8b3040eaa0b219e
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community