Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TheRabber's avatar

Inertia session update

Hi guys, as discussed in my other post ("Laravel inertia scope for client selection", I'm sadly not allowed to post links yet),

I would like to update my session based on a selection made in the frontend using inertia. As I'm new to inertia I'm looking for a best practice on how this could be done.

Just like in normal vue with using an axios? If yes, how would I secure the endpoint properly? Or is there some internal magic stuff from inertia I could use?

Thanks a lot in advance :)

0 likes
4 replies
gych's avatar

You can protect your API routes by using middleware. In your use case that would be the auth middleware.

Example

Route::middleware('auth')->get('/routepath', [YourController::class, 'controllerMethod']);
1 like
TheRabber's avatar

@gych Perfect, if that works fine with the axios as well I'm good to go

gych's avatar

@TheRabber Yes it will work, just add the route in your routes/web.php instead of routes/api.php otherwise it won't work with the regular cookie session.

TheRabber's avatar

@gych found an even easier way :) just use the router.post to send the data works fine

1 like

Please or to participate in this conversation.