Cannot get Ability to return true

Posted 3 years ago by cullymason

I am basically trying to set up an ability for a user to open and close a ticket . The logic is pretty simple, if the ticket is owned by the user, then you can open and close it. On a view, I want the Close Ticket button to only show when the ticket can be closed.

here are by abilities defined in the AuthServiceProvider

$gate->define('open-ticket',function($user,$ticket){
            return $user->id===$ticket->owner_id;
        });

$gate->define('close-ticket',function($user,$ticket){
            return $user->id === $ticket->owner_id;
});

In my view, I have

@can('close-ticket',$ticket)
 <a href="/tickets/{{$ticket->id}}/close" id="close-ticket-button" class="btn btn-danger-outline btn-block">Close Ticket</a>
@endcan

And the button never shows. I have checked the Database to make sure it is true. Then I simply changed the ability so it always returns true like this :

$gate->define('close-ticket',function($user,$ticket){
            return true;
});

And I get the same thing. Any ideas?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.