I have a Laravel PHP Photo Gallery application that allows the user to create an album and then insert photos into an album of their choice from a drop down list. This requires the user to create the album first since the drop down list is dynamic based on which albums actually exist. The drop down list is currently functioning properly but it does not display albums (array elements) alphabetically.
I've tried using the 'sort()' method but the problem is that the array element ids then become switched/re-sorted when doing so. I do not want the array ids to be re-sorted since this will put photos into the wrong albums.
So I want to know if there is a way to display the albums alphabetically in a drop down list while not re-sorting their array element ids.
Controller:
public function create()
{
$stoneArray = $this->stone->all()->toArray();
if (empty($stoneArray)) {
$dropdown[0] = 'There are no stones';
}
foreach ($stoneArray as $stone) {
$dropdown[$stone['stone_id']] = $stone['stone_name'];
// sort($dropdown); /* This re-sorted the array element ids */
}
$data = array('type' => 'stone_photo', 'dropdown' => $dropdown);
$this->layout->content = \View::make('forms.stones.new-photo', $data);
}
View:
<div class="form-group">
{{ Form::label('stone_id', 'Stone: ') }}
{{ Form::select('stone_id', $dropdown, array('class' => 'form-control')) }}
</div>
Any help is greatly appreciated! Thank you!