Answer the question
In order to leave comments, you need to log in
I can't get a selection through Eloquent Laravel - how to write a query correctly?
There are tables users and transports.
When fetching a vehicle, you need to check the city_id of the user to which the vehicle belongs, in order to get the vehicle only in a specific city.
users
id
city_id
transports
id
user_id
$transport = Transport::with(['user' => function ($query) use ($city_id) {
$query->where('city_id', $city_id);
}]);
Answer the question
In order to leave comments, you need to log in
whereHas('user', fucntion($query) use ($city_id) {
$qeury->where('city_id', $city_id);
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question