Support the ongoing development of Laravel.io →
posted 4 years ago
Laravel

Anyone can guide me that how to write an API for Roles and permission using Spatie (Laravel)p

Last updated 3 years ago.
0

add this to your user model: use HasRoles, HasPermissions; this would add the basic role/perms from spatie

then add protected $with = ['roles', 'permissions'];

it will autoload the values

then in your UserController, just return user object

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.