laravel entrust how to check a role's permission in blade?

时间:2017-08-04 12:17:15

标签: laravel entrust

I am using entrust in my laravel project. In blade file when I edit a role I want to display all the permissions with checkbox.

But I stuck at the thought that I want the checkbox status is checked if the role has the permission.I pass the role and all permissions to blade ,and try

@foreach($permissions as $permission)
  <input type="checkbox" value="{{$permission->name}}"
    @if($role->hasPermission($permission->name))
    checked="checked"
    @endif
@endforeach

but it didn't work

I also try convert $role and $permissions to array and pass them to blade and use foreach twice ,it didn't work either. Is there any way to make it?

2 个答案:

答案 0 :(得分:1)

你可以试试这个:

true

答案 1 :(得分:0)

证明$ role也可以调用hasPermission方法

 @foreach($permissions as $permission)
   <div class="checkbox pull-left" >
        <label class="">
            <input type="checkbox" name="perms[]" value="{{$permission->id}}" 
             @if($role->hasPermission($permission->name))  checked @endif>

          <p>{{$permission->display_name}}</p>
        </label>
   </div>
 @endforeach