how to use compact data in laravel view inside script [closed]

  html, jquery, laravel, select

I’ve list of medicine now I want to add a button to add medicine selection option. In the select tab doctor can search medicine name and select the medicine.

I’m passing data to laravel view template now I want to use this in option
how can I use foreach loop to show options inside script

    $(document).ready(function() {
    var max_fields = 30;
    var wrapper = $(".test");
    var add_button = $(".add_form_field");

    var x = 1;
    $(add_button).click(function(e) {
        if (x < max_fields) {
            $(wrapper).append('<div  class="form-group form-inline"><div><select class="livesearch form-control p-3"  name="mytext[]">'+

                @foreach ($collection as $item)
                       <option value="{{data->id}}">{{data->name}}</option>  

            +'</select><a href="#" class="delete glyphicon glyphicon-trash">DELETE</a></div></div>'); //add input box
        } else {
            alert('You Reached the limits')

    $(wrapper).on("click", ".delete", function(e) {

Source: Laravel

Leave a Reply