Reputation: 2000
hi i have a resource that returns the API JSON correctly now I want to show that data in HTML like the Laravel home page inside a MacBook SVG how can I access that JSON in my controller and send it to view because I already copied the MacBook and the code snippet of laravel.com so here is my code : resource :
public function toArray($request)
{
return parent::toArray($request);
}
and controller which is working fine as api now :
try {
$data = Accommodation::paginate(15);
} catch (\Exception $e) {
Log::error($e->getMessage());
throw new HttpException(500, $e->getMessage());
}
return new AccommodationResource($data);
now instead of that return of resource i want to return a view and send the $data as a json to it
Upvotes: 0
Views: 541
Reputation: 789
Just use it like this:
return view('your_view', ['data'=> json_encode($data)] );
Upvotes: 2