I am using Laravel blade and want to readonly select option if the authenticated user is not admin e.g in my code
<div class="form-group">
<label for="assigned_staffs">{{ trans('cruds.appointment.fields.assigned_staff') }}</label>
@if(auth()->user()->is_admin)
<div style="padding-bottom: 4px">
<span class="btn btn-info btn-xs select-all" style="border-radius: 0">{{ trans('global.select_all') }}</span>
<span class="btn btn-info btn-xs deselect-all" style="border-radius: 0">{{ trans('global.deselect_all') }}</span>
</div>
@endif
<select {{!auth()->user()->is_admin? 'readonly' :''}} class="form-control select2 {{ $errors->has('assigned_staffs') ? 'is-invalid' : '' }}" name="assigned_staffs[]" id="assigned_staffs" multiple>
@foreach($assigned_staffs as $id => $assigned_staff)
<option value="{{ $id }}" {{ (in_array($id, old('assigned_staffs', [])) || $appointment->assigned_staffs->contains($id)) ? 'selected' : '' }}>{{ $assigned_staff }}</option>
@endforeach
</select>
@if($errors->has('assigned_staffs'))
<div class="invalid-feedback">
{{ $errors->first('assigned_staffs') }}
</div>
@endif
<span class="help-block">{{ trans('cruds.appointment.fields.assigned_staff_helper') }}</span>
</div>
Here you can see on Select element I have used
{{!auth()->user()->is_admin? 'readonly' :''}}
As i want to make this select option readonly if user is not admin which is not working in laravel. it is working with textfields but not with Select Options elements.
I am using multiple select options so I will have array in assigned_staffs
e.g
<select multiple>
Note: I know about disabled attribute but If I use disbaled it will not submit my data for the field so cant use disabled here.
Please let me know how can I do this. Thank you