0

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

  • 4
    `readonly` does not work on `select` tags. You are probably looking for `disabled`. You should also just use `readonly` and not `readonly="readonly"` – D1__1 Apr 03 '23 at 12:07
  • Does this answer your question? [HTML form readonly SELECT tag/input](https://stackoverflow.com/questions/368813/html-form-readonly-select-tag-input) – D1__1 Apr 03 '23 at 12:08
  • I have seen this question you mentioned. I can see it works if we are selecting single select option but here I am using multiple selection in Select Tag e.g – Arslan Malik Apr 03 '23 at 12:31

0 Answers0