Reputation: 915
I have a foreach in a blade that loops through an array as follows :
@foreach($qwin as $qwinners)
<div>
<a href="" >{{$qwinners->title}}</a>
</div>
<br>
@endforeach
The above loop will result in 5 values. I want to store each of the 5 values in 5 Javascript variables to be used after that in javascript functions. How can this conversion be done in a blade?
Upvotes: 0
Views: 39
Reputation: 11034
You can assign an array plucked from the collection to a Javascript object like so
<script>
var qwinnners = {!! $qwin->pluck('id', 'title') !!};
</script>
Hope this helps
Upvotes: 1