Responses
Creating Responses
Creating an Inertia response is simple. To get started, invoke the Inertia::render() method within your controller or route, providing both the name of the JavaScript page component that you wish to render, as well as any props (data) for the page.
In the example below, we will pass a single prop (event) which contains four attributes (id, title, start_date and description) to the Event/Show page component.
1use Inertia\Inertia;23class EventsController extends Controller4{5 public function show(Event $event)6 {7 return Inertia::render('Event/Show', [8 'event' => $event->only(9 'id',10 'title',11 'start_date',12 'description'13 ),14 ]);1516 // Alternatively, you can use the inertia() helper...17 return inertia('Event/Show', [18 'event' => $event->only(19 'id',20 'title',21 'start_date',22 'description'23 ),24 ]);25 }26}1use Inertia\Inertia;23class EventsController extends Controller4{5 public function show(Event $event)6 {7 return Inertia::render('Event/Show', [8 'event' => $event->only(9 'id',10 'title',11 'start_date',12 'description'13 ),14 ]);1516 // Alternatively, you can use the inertia() helper...17 return inertia('Event/Show', [18 'event' => $event->only(19 'id',20 'title',21 'start_date',22 'description'23 ),24 ]);25 }26}
1<meta name="twitter:title" content="{{ $page['props']['event']->title }}">1<meta name="twitter:title" content="{{ $page['props']['event']->title }}">
1return Inertia::render('Event', ['event' => $event])2 ->withViewData(['meta' => $event->meta]);1return Inertia::render('Event', ['event' => $event])2 ->withViewData(['meta' => $event->meta]);
1<meta name="description" content="{{ $meta }}">1<meta name="description" content="{{ $meta }}">