1

How do I populate auth()->user()->first_name or {{ optional(auth()->user()->first_name) }} from my blade

Populate it using vue.js file.js to user.first_name code below?

var app = new Vue({
   el: '#property-booking',
    data: {
      user: {
        first_name: '',
        ......somecodes
      },
...Somecodes

Note: my.blade.php & vuefile.js file is separated

2
  • What you want is to pass user data from blade to vue component? Commented May 9, 2020 at 15:31
  • If it is possible. That's what I'm trying to do or to get the laravel auth data and pass it to vuejs Commented May 9, 2020 at 15:33

1 Answer 1

2

You could try using props.

This post may help you.

// blade

<component-name user={{ json_encode(auth()->user()) }}/>
var app = new Vue({
   el: '#property-booking',
   props: ['user']
...Somecodes

and use in your component like user.first_name, user.some_attribute

Hope it helps you.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, where I gonna put user.first_name ? Because I was trying to put data on my first_name: ' ', located on my vuefile.js

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.