[Vuejs]-Auth email in laravel template and vue component for display and data passing

1๐Ÿ‘

โœ…

If you are passing Auth::user()->email through the prop, like this:email="{{ Auth::user()->email }}" โ€“ you are able to use this.email in your vue component to access it, and send it through axios simple as this:

axios.post('/user', {
    email: this.email,
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

Also, if you want to have your auth user always available in your vue component you can do it by assigning it to window.user variable like this:

<script> window.user = {{ Auth::user() }}</script>

Then in your vue component you can do something like this window.user.email and such.

Also, I encourage you to take a look at this article โ€“ it will give you some more examples.

Hope this helps.

๐Ÿ‘คBen

Leave a comment