rupadana / filament-api-service

A simple api service for supporting filamentphp
https://filamentphp.com/plugins/rupadana-api-service
MIT License
140 stars 28 forks source link

[Bug]: Call to undefined method App\Models\User::hasRole() #74

Closed jhayg12 closed 3 weeks ago

jhayg12 commented 4 weeks ago

What happened?

This error shows up when trying to create a token from the Token Resource

image

How to reproduce the bug

Just follow the steps here https://filamentphp.com/plugins/rupadana-api-service#installation up to creating of tokens on the Token Resource on the admin portal

Package Version

^3.3

PHP Version

8.2

Laravel Version

11.9

Which operating systems does with happen with?

Windows

Notes

The endpoint works when set to public but I want it to be secure so would want to have a token created for the two app to communicate using it

rupadana commented 4 weeks ago

make sure u already use HasRoles trait at the User model

Aliyan-12 commented 3 weeks ago

The issue is because you have not included the hasRoles trait of spatie/laravel-permissions in you User model

use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles; //Ensure it is included here.

    // ...
}

You can check the spatie/laravel-permissions documentation here: https://spatie.be/docs/laravel-permission/v6/basic-usage/basic-usage

If you are still getting the issue, you need to verify the version compatibility for laravel ^11.9 that is ^6.0. You can check it here: https://spatie.be/docs/laravel-permission/v6/installation-laravel

If you are using any package other than spatie/laravel-permissions then you need to check the package documentation for how to use the roles in user model.

Hope this might help. 💯 👍.