mardi 6 octobre 2020

Error when trying to create an user with JWTAuth in Laravel

I'm trying to make a simple auth API to get tokens with JWTAuth with PHP and Laravel, but I get this error every time when I try to create a user:

[Tue Oct  6 07:21:21 2020] 127.0.0.1:56819 Accepted
[Tue Oct  6 07:21:22 2020] 127.0.0.1:56819 Closing
[Tue Oct  6 07:21:31 2020] 127.0.0.1:56820 Accepted
[Tue Oct  6 07:21:31 2020] PHP Fatal error:  Class App\Models\User contains 1 abstract method and must
 therefore be declared abstract or implement the remaining methods (Tymon\JWTAuth\Contracts\JWTSubject::getJWTCustomClaims) 
in E:\_Code\laravel\ApiDevBarber\app\Models\User.php on line 10
[Tue Oct  6 07:21:33 2020] 127.0.0.1:56820 Closing

This error throws at both Insomnia, Rest test test, and Advanced REST client. I've followed the Laravel's and JWT documentation to write the User.php, below is the entire code.

<?php

namespace App\Models;

use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    protected $hidden = ['password'];

    public $timestamps = false;

    public function getJWTIdentifier() {
        return $this->getkey();
    }

    public function getJWTCustomClains() {
        return [];
    }
}

I'm new at PHP and Laravel, am I missing something?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire