Skip to content

Commit 9d42207

Browse files
committed
Update docs with new "withViewData" method
1 parent 6067b7c commit 9d42207

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

readme.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ class EventsController extends Controller
7474
}
7575
~~~
7676

77+
Alternatively, you can use the `with()` method to include component data (props):
78+
79+
~~~php
80+
use Inertia\Inertia;
81+
82+
class EventsController extends Controller
83+
{
84+
public function show(Event $event)
85+
{
86+
return Inertia::render('Event')
87+
->with('event', $event->only('id', 'title', 'start_date', 'description'));
88+
}
89+
}
90+
~~~
91+
7792
## Following redirects
7893

7994
When making a non-GET Inertia request, via `<inertia-link>` or manually, be sure to still respond with a proper Inertia response. For example, if you're creating a new user, have your "store" endpoint return a redirect back to a standard GET endpoint, such as your user index page. Inertia will automatically follow this redirect and update the page accordingly. Here's a simplified example.
@@ -133,17 +148,16 @@ There are situations where you may want to access your prop data in your root Bl
133148
<meta name="twitter:title" content="{{ $page['props']['event']->title }}">
134149
~~~
135150

136-
Sometimes you may even want to provide data that will not be sent to your JavaScript component. You can do this using the `with()` view helper, since `Inertia::render()` returns a `View` instance.
151+
Sometimes you may even want to provide data that will not be sent to your JavaScript component. You can do this using the `withViewData()` method.
137152

138153
~~~php
139-
return Inertia::render('Event', ['event' => $event])
140-
->with(['meta_description' => $event->meta_description]);
154+
return Inertia::render('Event', ['event' => $event])->withViewData(['meta' => $event->meta]);
141155
~~~
142156

143157
You can then access this variable like a regular Blade variable.
144158

145159
~~~blade
146-
<meta name="description" content="{{ $meta_description }}">
160+
<meta name="description" content="{{ $meta }}">
147161
~~~
148162

149163
## Asset versioning

0 commit comments

Comments
 (0)