vendredi 17 février 2017

Authorization from model

I have a Board.php model with a method checkViewAccess()

i.e

@if($board->checkViewAccess())
    render board
@endif

It does a few checks, and on the last check it needs to call a policy method to determine authorization for the user.

  • In blade, @can('view', $board) works
  • In controllers, $this->authorize('view', $board) works

But I cannot for the life of me find out any way to call a policy authorization from the Board model

What I've tried:

  • Gate::check('view', $this) // Non-static method, which is fine, didn't expect it to work
  • auth()->user()->can('view', $this) // This doesn't even hit the policy and returns false regardless of what I return from the policy. Even if I just return true in the before() policy method it's false

So how can I achieve this? How can I access laravels authorization from a model?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kx9mpW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire