Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KillerCookie's avatar

disable form select option if user ist not a developer

Hello Guys,

is there any option to disable select options if user is not a developer

here is my code snippet:

<div class="col-md-2">
       <div class="form-group">
              <label for="confirm-password">Berechtigung</label>
              {!! Form::select('roles[]', $roles,[], array('class' => 'form-control user-role')) !!}
      </div>
</div>

my output:

  • Developer
  • Admin
  • Standard

So but i want that an admin can only select

  • Admin
  • Standard

So how can i do that?

0 likes
2 replies
Charizard's avatar

I would check on the controller side before passing the $roles variable to your views, so something like this:

if(auth()->user()->isAdmin())
	$roles = ['Admin', 'Standard'];

return view('myview', compact('roles'));
KillerCookie's avatar

so I tried your solution but ist doesn`work.

That´s my controller snippet:

if(!auth()->user()->roles()->where('name', 'Developer')->exists()) {
            $roles = Role::pluck('name','name')->without('Developer');
        } else {
            $roles = Role::pluck('name','name')->all();
        }

        return view('users.create',compact('roles'));

I think I understand something wrong.

Please or to participate in this conversation.