Saad
Saad

Reputation: 1221

Entrust Facade @role not working on Laravel 5.1

I installed Zizaco/entrust (https://github.com/Zizaco/entrust) with laravel 5.1 and added these in the provider and aliases array

'providers' => [
....
Zizaco\Entrust\EntrustServiceProvider::class,
]
'aliases' => [
....
'Entrust'   => Zizaco\Entrust\EntrustFacade::class,
]

I can access all the Entrust functionalities from controllers eg: $user->hasRole('admin') with no problems however when I try this in my view it doesn't work

@role('admin')
....
@endrole

It simply shows @role('admin') @endrole as html. So I tried

@if(\Entrust::role('admin'))
...
@endif

And I get

Call to undefined method Zizaco\Entrust\Entrust::role()

Do I have to perform any additional configuration or changes to make @role work? Or am I missing something?

Thanks in advance

Upvotes: 2

Views: 1751

Answers (2)

It works for Laravel 5.1.31 LTS

  1. So simply replace your file in the Vendors/Zizaco/entrust/src/Entrust/EntrustServiceProvider.php with the file below: https://github.com/Zizaco/entrust/blob/master/src/Entrust/EntrustServiceProvider.php
  2. After that you can do php artisan view:clear
  3. Then you can see error Call to undefined method Zizaco\Entrust\Entrust::ability()
  4. That easy to solved Entrust::ability error you can replace file Vendors/Zizaco/entrust/src/Entrust/Entrust.php with https://raw.githubusercontent.com/Zizaco/entrust/master/src/Entrust/Entrust.php

Upvotes: 0

Saad
Saad

Reputation: 1221

I couldn't get @roles('admin') to work but this works

@if(Entrust::hasRole('admin'))
....
@endif

Upvotes: 1

Related Questions