Did you add the HasRoles trait to the User model?
Call to undefined method App\Models\User::assignRole()
I keep getting this error eventhough I have used Spatie libraries in user's model BadMethodCallException
Call to undefined method App\Models\User::assignRole()
at E:\xampp\htdocs\authentication2\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php:71 67▕ * @throws \BadMethodCallException 68▕ */ 69▕ protected static function throwBadMethodCallException($method) 70▕ { ➜ 71▕ throw new BadMethodCallException(sprintf( 72▕ 'Call to undefined method %s::%s()', static::class, $method 73▕ )); 74▕ } 75▕ }
• Bad Method Call: Did you mean App\Models\User::asJson() ?
1 E:\xampp\htdocs\authentication2\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php:36 Illuminate\Database\Eloquent\Model::throwBadMethodCallException("assignRole")
2 E:\xampp\htdocs\authentication2\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:2132 Illuminate\Database\Eloquent\Model::forwardCallTo(Object(Illuminate\Database\Eloquent\Builder), "assignRole")
@bishal123 Your model should look like
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
// ...
You need to HasRoles inside the model itself.
Please or to participate in this conversation.