I am fetching data from two tables using join, however, I want my result to return a multi-dimensional array , i.e.
FRUITS
- Apple
- Mango
- Orange
Animal
- Dog
- Cat
- Cow
Country
- Germany
- UK
- USA
So, that is what I want it to return, see my code below
Route::get('all-category', function(){
$category = DB::table('directory_companies')
->join('categories','directory_companies.categories_id', '=', 'categories.id')
->select('categories.name', 'directory_companies.*')
->get();
return response()->json($category);
How do I return it to display like the list above in multidimensional array, I am using Laravel to build the API