/** * Display a listing of the resource. * * @return Response */ public function index() { $trashes = Trash::all(); //long route to do this //dd($trashes); $trashesArray = []; foreach ($trashes as $trash) { $array = $trash->toArray(); $array['types'] = $trash->types->pluck('type')->toArray(); $trashesArray[] = $array; } $trashes = collect($trashesArray); return $trashes; //return response()->json($trashesArray, 200)->header('Access-Control-Allow-Origin', '*'); }