I followed this topic on getting list of roles and permissions through user model using spatie/laravel-permission but none are engaging on my kind of concern.
Want to retrieve list of roles related to user using spatie/laravel-fractal through $user->roles
and $user->permissions
just like zizaco/entrust when I call fractal($user, new UserTransformer)->parseIncludes(['roles', 'permissions'])->toArray();
, used $this->collection($user->roles, new RoleTranformer)
in UserTranformer.php but throws Symfony\Component\Debug\Exception\FatalThrowableError
. I am building an API project using laravel 5.7 and spatie/laravel-permission and spatie/laravel-fractal so trying to organise json response using relations.
Asked
Active
Viewed 160 times
0

apokryfos
- 38,771
- 9
- 70
- 114

Timothy Kimemia
- 1
- 2
-
What are the versions of your `PHP` and `spatie/laravel-fractal` – zlatan Jun 20 '19 at 08:03
-
using `php: 7.2` and `spatie/laravel-fractal: ^5.5` but problem is with `spatie/laravel-permission` cannot fetch collection when using `$user->roles` – Timothy Kimemia Jun 20 '19 at 08:24
-
Got the problem, recommends use of `\Spatie\Permission\Models\{Role, Permission}` rather than custom `\App\Models\{Role, Permission}`. to be namespaced in `Role::transform()`. – Timothy Kimemia Jun 24 '19 at 15:34