Reputation: 733
I am using Laravel 5.2 with Zicaco Entrust for the management of permissions and roles.
I have a menu for the user and I use the laravel blade system in order to show the menu with @permission for each menu section because I am only showing the menu section if the user has the permission to see it.
@permission(['upload'])
<ul class="nav side-menu">
<li><a><i class="fa fa-home"></i>DB Feed <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
@permission(['file-upload'])
<li><a href="{!!route('uploadform')!!}">file upload</a></li>
@endpermission
@permission(['***-upload'])
<li><a href="{!!route('***uploadform')!!}">*** upload</a></li>
@endpermission
@permission(['***-upload'])
<li><a href="{!!route('***uploadform')!!}">*** upload</a></li>
@endpermission
@permission(['***-upload'])
<li><a href="{!!route('***uploadform')!!}">*** upload</a></li>
@endpermission
</ul>
</li>
</ul>
@endpermission
And it continues like this as I have something like 50 different @permission in my menu section.
Now when I look the different mysql access, I can see that it does 50 times the same request to the DB:
select `roles`.*, `role_user`.`user_id` as `pivot_user_id`, `role_user`.`role_id` as `pivot_role_id` from `roles` inner join `role_user` on `roles`.`id` = `role_user`.`role_id` where `role_user`.`user_id` = '1'
select `permissions`.*, `permission_role`.`role_id` as `pivot_role_id`, `permission_role`.`permission_id` as `pivot_permission_id` from `permissions` inner join `permission_role` on `permissions`.`id` = `permission_role`.`permission_id` where `permission_role`.`role_id` = '1'
How can I change this behavior so that it does only 1 single set of request?
Thanks.
Upvotes: 0
Views: 33
Reputation: 733
Ok, so it seems that the Entrust addon to Laravel is not developped anymore. I could find a solution though through the cache.php file in the config folder and add the following line:
'ttl' => 30 //In minutes
Upvotes: 0