Answer the question
In order to leave comments, you need to log in
How to specify fields to fetch in eloquent eager loading?
This query works fine, but returns all the fields from both tables,
$cities = City::with(['city_translates'=>function($query) use ($lang_id){
$query->where('language_id',$lang_id);
}])
->get()
->toJson();
$cities = City::with(['city_translates'=>function($query) use ($lang_id){
$query
->select('name')
->where('language_id',$lang_id);
}])
->get()
->toJson();
$cities = City::with(['city_translates' => function ($query) use ($lang_id) {
$query
->where('language_id', $lang_id);
}])
->select('name')
->get()
->toJson();
Answer the question
In order to leave comments, you need to log in
$query
->select('name')
->where('language_id',$lang_id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question