Answer the question
In order to leave comments, you need to log in
How to specify the required fields in relations?
Tried many ways and none of them worked.
News::query();
if ($request->has('is_hidden')) {
$query->where('is_hidden', 1);
}
if ($request->has('is_moderated'))
$query->where('is_moderated', 1);
$list = $query->with(array('source' => function ($query) {
$query->select(['id', 'url', 'name']);
}))->select(['id', 'image_url', 'published', 'added', 'header']);
News::query();
if ($request->has('is_hidden')) {
$query->where('is_hidden', 1);
}
if ($request->has('is_moderated'))
$query->where('is_moderated', 1);
$list = $query->with(array('source' => function ($query) {
$query->get(['id', 'url', 'name']);
}))->get(['id', 'image_url', 'published', 'added', 'header'])
if ($request->has('is_hidden')) {
$query->where('is_hidden', 1);
}
if ($request->has('is_moderated'))
$query->where('is_moderated', 1);
$list = $query->with('source')->get();
Answer the question
In order to leave comments, you need to log in
Common problem. Solved by adding the key to the select list :
$list = $query->with(array('source' => function ($query) {
$query->select(['id', 'url', 'name', 'key_field']);
}))->select(['id', 'image_url', 'published', 'added', 'header']);
You have a small error in the first option, you don't need to pass an array to select, but just fields separated by commas
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question