Only until March 18th: coupon LARAVEL12 for 40% off Yearly/Lifetime membership!

Read more here
Courses

Vue Inertia + Laravel 11: From Scratch

Show User Data in Header

Summary of this lesson:
- Sharing user data via HandleInertiaRequests Middleware
- Accessing user information in Vue layout
- Displaying logged-in user's name and email
- Passing data without explicitly defining props

In this short lesson, instead of hard-coded Hi, user, let's show the actual logged-in user.


To show the user, we will use the same concept of sharing data by adding it to the HandleInertiaRequests Middleware. Let's pass only the name and email.

app/Http/Middleware/HandleInertiaRequests.php:

class HandleInertiaRequests extends Middleware
{
// ...
 
public function share(Request $request): array
{
return array_merge(parent::share($request), [
'flash' => [
'message' => fn () => $request->session()->get('message')
],
'user' => [
'name' => $request->user()?->name,
'email' => $request->user()?->email,
],
]);
}
}

Now, we can access these values using...

The full lesson is only for Premium Members.
Want to access all 18 lessons of this course? (56 min read)

You also get:

  • 71 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord