Answer the question
In order to leave comments, you need to log in
How to filter records using Eloquent?
Tables
Cars
- id
- name
- user_id
Models
- id
- car_id
- title
How to get cars (Car) whose name is more than 10 characters and only if it has at least one (Model) from the User model.
The question is not about hasMany, BelongsTo, but how to arrange this check? How many documentation I do not read, I can not figure it out, please help.
Now the code looks like this..
/**
* Get the all Cars with Models by me.
*/
public function cars()
{
return $this->hasMany('App\Cars')->with('models');
}
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