0

I am using the following code:

<select onchange="javascript:location.href = this.value;">

<option value="" selected>-- Show Genre --</option>

@foreach ($genres as $genre)
<option value="{{ URL::route('tracks.order', array('order' => 'name', 'by' => 'asc', 'genre' => $genre->name )) }}">{{ $genre->name }}</option>
@endforeach

</select>

The $genres is populated using the following code in my controller:

$genres     = Genres::lists('name', 'id');

I was wondering if I could use a code like below instead of the foreach? I think I should be able to, but I have no clue on how to change the code to work with my code above.

{{ Form::select('genre', array('default' => '-- Select Genre --') + $genres, '') }}
1
  • Which version of Laravel are you using? Commented Jul 31, 2015 at 20:19

1 Answer 1

1

You may try something like this:

$genres = ['default' => '-- Select Genre --'] + Genres::lists('name', 'id');

In the view:

{{ Form::select('genre', $genres, Form::old('genre')) }}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but that is not what I meant, sorry for being unclear. I would like to know if it's possible to have the {{ Form::select with this: <option value="{{ URL::route('tracks.order', array('order' => 'name', 'by' => 'asc', 'genre' => $genre->name )) }}">{{ $genre->name }}</option> ?
Yes, it's possible :-)

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.