Reputation: 892
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:\xampp\htdocs\laralast\resources\views\view.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.
Upvotes: 0
Views: 67
Reputation: 3712
Please Check This use if & else
<select class="form-control" name="assign_to" id="assign_to">
<option selected disabled>Select support</option>
@foreach($supports as $support)
@if($ticket->assign_by == $support->id)
<option value="{{$support->id}}" selected>{{$support->fullname}}
</option>
@else
<option value="{{$support->id}}">{{$support->fullname}}</option>
@endforeach
</select>
Upvotes: 1
Reputation: 1951
You should quote your string
(I mean you should quote the selected
):
<option value="{{$support->id}}" {{($ticket->assign_by == $support->id ? 'selected' : '')}}>{{$support->fullname}}</option>
Your laravel is understanding that you will print the value of selected
constant (since no dollar-sign $
, no string quotation ''
""
) when the condition is true
.
Upvotes: 1