Jun 9, 2021
0
Level 1
Print select options accordingly user's permission
Hi Friends, Hope you are doing well.
I'm using spatie's permission package to manage my user's role and permissions.
I have 4 roles
- Admin
- Super Distributor
- Distributor
- Retailer
in my user creation from i fetched all roles using Spatie\Permission\Models\Role role model... and foreach looped to generate select values but the twist comes here.
Admin can create every type of user but super distributor can only create distributor and retailer, distributor can only create retailer. how to i generate options accordingly user roles?
Currently i wrote this code and its not working at all
<select wire:model="role" name="role" class="block mt-1 w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm block mt-1 w-full">
<option value="" selected>Please select an option</option>
@forelse ($roles as $role)
@role('admin')
@if ($role == 'admin' || $role == 'super distributor' )
<option value="{{ $role->name }}">{{ Str::ucfirst($role->name) }}</option>
@endif
@endrole
@empty
<option >There is no roles available</option>
@endforelse
</select>
Please or to participate in this conversation.