dagitab
dagitab

Reputation: 133

Inertia.js and Laravel - How does the view automatically receive the auth::user() object?

I am currently working on a Laravel 8 project and for the first time, I tried using the provided Laravel Breeze scaffolding with Inertia.js and Vue. In the original dashboard scaffolding, the dashboard component can automatically retrieve the $page.props.auth.user object, as shown in the image: enter image description here

However, if you look at the <script> part of the Vue component, the props for these objects aren't there.

My question is, how does Laravel pass the auth object to the $page variable?

I am not sure if my purpose will further help in answering that question, but I'm gonna say it anyway: I have made a polymorphic relationship between two models (a User model and a Student model) and I wanted the auth.user object to also contain information from the associated row in Student every request, since I'm gonna use it to display names and other details on a sidebar/navbar. enter image description here

enter image description here

Thank you in advance for all your help!

Upvotes: 0

Views: 3424

Answers (2)

Samuele
Samuele

Reputation: 9

Inside

app\Http\Middleware\HandleInertiaRequests.php

in share function

Upvotes: 0

Matheus Dal&#39;Pizzol
Matheus Dal&#39;Pizzol

Reputation: 6105

The $page.props.auth.user comes from the share method at \app\Http\Middleware\HandleInertiaRequests.php middleware.

I've explained a little bit about this middleware on another answer you can read here.

You won't see the prop on the page component because it's a shared property. Give a closer look at the docs on this.

Upvotes: 3

Related Questions