0

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?

1 Answer 1

1

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

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

Comments

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.