Skip to content Skip to sidebar Skip to footer

Pass Array To Laravel View And Use That Array As Vuejs Prop

I have an array variable $screenshots that I am trying to pass to my Laravel view. Usually, I would use the @foreach and loop through the array, but I want to pass the full array t

Solution 1:

This works - it was hard to find this answer on the web so I hope it helps! You have to bind it.

 <edit-ticket-template
      v-bind:SingleTicket="{{  json_encode($ticket) }}"
      v-bind: screenshots ="{{  json_encode($files) }}"
  >
  </edit-ticket-template>

Yeah I don't think you need to json_encode the single ticket but you get the point.

Solution 2:

I think Blade calls htmlentities() automatically when you write {{ $ticket }}. Since $ticket is not a string, it is erroring. Try {{ json_encode($ticket) }}

Solution 3:

You should use {!! json_encode($ticket) !!}}

Solution 4:

I use Laravel 7 and I faced the same problem. and I use this solution and do

 {!! json_encode($ticket) !!}}

Perhaps there is a better solution. !!!

Solution 5:

Alternatively, turn your $files array into a Collection using collect($files) before you pass it to the view (i.e. in your Controller) – this way, Laravel will handle the JSON encoding for you on the fly, so you can just bind it to your component's property in the way you had originally proposed, i.e.

<ticket-edit id="edit-ticket" single-ticket="{{ $ticket }}" screenshots="{{ $files }}">

Post a Comment for "Pass Array To Laravel View And Use That Array As Vuejs Prop"