[Vuejs]-Getting parent json data in child level loop. (Laravel Vue js)

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.

Leave a comment