mercredi 8 juillet 2015

Conditional @if statement for preselected options in Laravel 5 form using Blade templates

In creating an update form using the same template as the create form, I wish to have the previously chosen options selected. Something like this makes sense, but Blade cannot parse it:

{!! Form::select('number', [1, 2, 3, 4, 5] @if (!empty($at)), $at->id @endif) !!}

I use the $at variable to identify if I'm updating or creating a new entry.

I could write 2 separate statements and echo whichever one is relevant (or use a separate template, but I'm trying to keep the code DRY.

Aucun commentaire:

Enregistrer un commentaire