https://laravel.com/docs/5.0/eloquent#query-scopes
http://laravel.at.jeffsbox.eu/laravel-5-eloquent-scopes-dynamic-scopes
https://laravel.com/docs/8.x/eloquent#query-scopes
Query Scopes
Defining A Query Scope
Scopes allow you to easily re-use query logic in your models. To define a scope, simply prefix a model method with scope:
class User extends Model {
public function scopePopular($query)
{
return $query->where('votes', '>', 100);
}
public function scopeWomen($query)
{
return $query->whereGender('W');
}
}
https://stackoverflow.com/questions/39277768/laravel-5-global-scope-with-dynamic-parameter
public function scopeForManager($query, $manager)
{
return $query->where('manager', $manager->id);
}
Document::forManager($manager)->all();
No comments:
Post a Comment