Answer the question
In order to leave comments, you need to log in
How to hide complex query in eloquent model?
Good afternoon.
It is necessary to hide a lot of complex queries to the database in simple methods of the model. It concerns many models, so there are no options to create a query builder for each.
Example.
public function available() {
return $this->where('id', 1)
}
public function withSomeMore($l) {
return $this->whereHas('smth', function ($q) use($l) {
$q->where('q', 1);
}
}
// Вызов функции
$model->available()->withSomeMore()->get();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question