0๐
โ
I got the answer from here:
Select from multiple tables with laravel fluent query builder
so, i changed this:
return parent::with('children')->get();
to this:
return DB::table('parent')
->join('children', 'parent_id', '=', 'parent.id')
->get(array(
'name',
'parent_name'
));
but first i changed the name
field in parent
table to parent_name
0๐
Define the reverse relationship between Children and Parent, in which you will return the parent model with every children; and then in your controller you return all record that have a non-null parent with their parents
return Model::where("parent_id", "<>", null)->with("parent")->get();
and then in your VueJS app you will have a JSON response of all children models along with their parents.
Source:stackexchange.com