vendredi 6 novembre 2015

Laravel ACL Troubleshooting

I'm currently using Laravel 5.1.11. I was previously on 5.1.6 I believe, but anyway, I performed the upgrade according to the guide: http://ift.tt/1P9brzd

I wanted to use the ACL feature, but am having issues with it, and I'm not quite sure how to resolve it.

  • The Gate facade is registered, and when I use it, it's telling me that the denies() method is undefined. It's imported in my controller, and the code snippet I tested with is:

    if ( Gate::denies('createOrder') )
    {
        return 'false';
    }
    
    
  • If I try to use the authorize method from the controller, I can't ever pass. Even if I simply return true in the policy object, in the before() method, I can't pass. And what's weird is that even if I use an ability that isn't defined anywhere, it doesn't show any kind of error or anything. It just denies me. I wasn't sure if it's supposed to happen that way. The line of code I used to test was:

    $this->authorize('createOrder');
    $this->authorize('test');

  • I've even tried authorizing from the user model, and that doesn't work either (it returns 'false'). The snippet is:

    if ( Request::user()->cannot('createOrder') )
    {
        return 'false';
    }
    
    

I have an OrderPolicy object, and like I mentioned, I'm just returning true in the before() method. So it should always let me pass.

So I've run out of ideas on how to solve this. If anyone can give me some ideas, that'd be great. Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire