'Spatie Roles and Permissions with Laravel Sanctum Authentication for API

I have built an API in Laravel using Sanctum for authentication. This is working great. I am now able to login in Postman to retrieve my token, then use that token to authenticate further requests.

I have also implemented Spatie Roles and Permissions for granular user permissions. Again, this is working fine. In my unit tests I create a new factory user, assign it the permissions I am testing and verify features are either authorised or unauthorised.

My problem is combining the two. How can I use Postman to login using Sanctum whilst honouring the Spatie permissions assigned to my logged in user? Every attempt I make authenticates me fine, but does not authorise me for anything.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source