Laravel_api/app/Models/User.php

58 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2019-03-01 14:08:34 +08:00
<?php
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'password'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password'
];
//将密码进行加密
public function setPasswordAttribute($value)
{
$this->attributes['password'] = bcrypt($value);
}
2019-03-23 09:39:05 +08:00
public function books(){
return $this->hasMany(Book::class,'user_id','id')->limit(2);
}
2019-03-01 14:08:34 +08:00
}