0

I am having issues trying to figure something out. I pass my view an array of data which takes the following form

array:4 [▼
  "data" => array:2 [▼
    2015 => array:2 [▼
      "english" => array:1 [▼
        "chips" => array:1 [▼
          0 => "img1.png"
        ]
      ]
      "french" => array:1 [▼
        "mussles" => array:1 [▼
          0 => "img1.png"
        ]
      ]
    ]
    2016 => array:2 [▼
      "indian" => array:1 [▼
        "madras" => array:1 [▼
          0 => "img1.png"
        ]
      ]
      "italien" => array:1 [▼
        "pasta" => array:1 [▼
          0 => "img1.png"
        ]
      ]
    ]
  ]
]

This stucture is obtained from scanning a directory structure, but it should be pretty consistent. The overall structure is

Year>Country>Dish>Images

I need to somehow display this data within select options. So year is pretty straight forward, I can do this

<select id="yearSelection" class="selectpicker form-control">
    @foreach($fileData["data"] as $year => $country)
        <option value="{{ $year }}">{{ $year }}</option>
    @endforeach
</select>

Here is my problem. So the above select will display 2015 and 2016. I then have a second select input

<select id="countrySelection" class="selectpicker form-control">
    <option value=""></option>
</select>

Now depending on what year they select is going to determine what this select should display. So if they select 2015, this select should display english and french.

How can I populate my select options based on previous selections?

Cœur
  • 37,241
  • 25
  • 195
  • 267
katie hudson
  • 2,765
  • 13
  • 50
  • 93

1 Answers1

0

You will need to use AJAX to accomplish this in a smooth-looking way.

Or you could refresh when your selected option changes and send the selected year (and other data) using GET parameters. Then you can just pass your data on to the view depending on your GET parameters.

This should point you to the direction you want to go.