I’m trying to dynamically the select option selected just using php in laravel but I’m getting this error:
Use of undefined constant selected – assumed ‘selected’ (this will
throw an Error in a future version of PHP) (View:
C:xampphtdocslaralastresourcesviewsview.blade.php)
below is my view blade
<select class="form-control" name="assign_to" id="assign_to">
<option selected disabled>Select support</option>
@foreach($supports as $support)
<option value="{{$support->id}}" {{($ticket->assign_by == $support->id ? selected : '')}}>{{$support->fullname}}</option>
@endforeach
</select>
Can you help me with this.
2
Answers
You should quote your
string
(I mean you should quote theselected
):Your laravel is understanding that you will print the value of
selected
constant (since no dollar-sign$
, no string quotation''
""
) when the condition istrue
.Please Check This use if & else