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

anonymouse703's avatar

How to get the aut()->user()->name in laravel-vue?

My current set-up is I put in the meta but it's not safer... what are the best recommendations for this?

current setup

in app.blade.php

 <meta name="user-name" content="{{ auth()->user()->name ?? '' }}">

then in the topbar.vue

const userName = ref('');

onMounted(() => {
    userName.value = document.querySelector("meta[name='user-name']").getAttribute('content');
});

then

  <li class="p-2">
    <div class="font-medium">{{ userName }}</div>
    <div class="text-xs text-white/60 mt-0.5 dark:text-slate-500">Admin</div>
</li>

but it's safe right?

0 likes
2 replies
gych's avatar
gych
Best Answer
Level 29

You can use the page props for this

<div class="font-medium">{{ $page.props.auth.user}}</div>
1 like

Please or to participate in this conversation.