Skip to content

Instantly share code, notes, and snippets.

@brasizza
Created December 15, 2020 01:54
Show Gist options
  • Save brasizza/d94e24fdd6f2f1a5f3443c270e0b16f1 to your computer and use it in GitHub Desktop.
Save brasizza/d94e24fdd6f2f1a5f3443c270e0b16f1 to your computer and use it in GitHub Desktop.
<?php
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;
use Laravel\Lumen\Auth\Authorizable;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
{
use Authenticatable, Authorizable, HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password',
];
public function getJWTIdentifier() {
return $this->getKey();
}
public function getJWTCustomClaims() {
return [];
}
public function setPasswordAttribute($val){
$pass = Hash::make(($val));
$this->attributes['password'] = $pass;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment