0

Chats.php

<ChatsComponent :user="{{ Auth::user()}}" />

in ChatsComponent.php

<template>
 <div  class="container font-sans antialiased h-screen flex">
 <span class="font-bold">{{user.name}}</span>
 </div>
</template>



<script>
export default {
props:['user'],
}
</script

I dont know why i get this error iam using laravel8.x with innertia + vue

2
  • 1
    What is the purpose of :user="{{Auth::user()}}"? This is prop syntax and div is not a component. If you accept "user" as props, why do you use Laravel syntax in Javascript, BTW, it's not possible as far as I know. So your problem is there but the code doesn't make your intention clear. Commented Mar 16, 2021 at 19:01
  • Now looks good, but you are still trying to use a Laravel code in Js. It's not possible. Laravel codes are executed in the server while Js in the browser. Commented Mar 16, 2021 at 20:36

2 Answers 2

1

Try to add !! inside the brackets like :

<ChatsComponent :user="{{!! Auth::user() !!}}" />
Sign up to request clarification or add additional context in comments.

3 Comments

still deos not work, ive no idea couse im new to laravel and vue
try it out without binding sign user="{{ Auth::user()}}"
your file should be named Chats.blade.php
0

my solution is that i can't use Laravel syntax in javascript as they mentioned in the comment so i get user detail via controller and assign to props

is it a good practice? i don't know.

1 Comment

I recommend you to use Vuex, So at login, you can save that user to Store and retrieve easily anywhere in your Vue code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.