Created
March 29, 2022 19:55
-
-
Save dersonsena/98a275100d2864be2842886657e155ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Shared\Infra\Models; | |
use Illuminate\Auth\Authenticatable; | |
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; | |
use Illuminate\Database\Eloquent\Factories\HasFactory; | |
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject; | |
class User extends ModelBase implements | |
AuthenticatableContract, | |
JWTSubject | |
{ | |
use HasFactory; | |
use Authenticatable; | |
protected $fillable = [ | |
'id', | |
'name', | |
'group', | |
'username', | |
'email', | |
'password', | |
'active', | |
'verification_code', | |
'indication_code', | |
'created_by' | |
]; | |
protected $hidden = [ | |
'password', | |
'uuid' | |
]; | |
protected $casts = [ | |
'email_verified_at' => 'datetime', | |
'created_at' => 'datetime:' . DATE_ATOM, | |
]; | |
public function customer() | |
{ | |
return $this->hasOne(Customer::class, 'id'); | |
} | |
public function getJWTIdentifier(): string | |
{ | |
return $this->getKey(); | |
} | |
/** | |
* Return a key value array, containing any custom claims to be added to the JWT. | |
* @return array | |
*/ | |
public function getJWTCustomClaims(): array | |
{ | |
return [ | |
'name' => $this->name, | |
'username' => $this->username, | |
'group' => $this->group, | |
'indicationCode' => $this->indication_code, | |
'isActive' => $this->active === 1, | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment