vd/app/Models/Account/Account.php
2019-01-17 11:32:21 +08:00

106 lines
4.6 KiB
PHP

<?php
namespace App\Models\Account;
use App\Core\Model;
use Illuminate\Auth\Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;
use App\Models\Permission\Traits\HasRoles;
use Dipper\Foundation\Nestedset\NodeTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
/**
* 账号
*
* @property int $id 账户ID
* @property string $username 登录名
* @property string $nickname 昵称
* @property string $email 邮箱
* @property string $mobile 手机号
* @property string $password 密码
* @property string $salt 盐
* @property int $status 状态 0未激活 1正常 2禁用
* @property int $_lft
* @property int $_rgt
* @property int $parent_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property-read \Dipper\Foundation\Nestedset\Collection|\App\Models\Account\Account[] $children
* @property-read \App\Models\Account\Account $parent
* @property-read \Dipper\Foundation\Nestedset\Collection|\App\Models\Permission\Permission[] $permissions
* @property-read \Dipper\Foundation\Nestedset\Collection|\App\Models\Permission\Role[] $roles
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account d()
* @method static bool|null forceDelete()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account newQuery()
* @method static \Illuminate\Database\Query\Builder|\App\Models\Account\Account onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account permission($permissions)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account query()
* @method static bool|null restore()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereLft($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereMobile($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereNickname($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereParentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereRgt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereSalt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Account\Account whereUsername($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Account\Account withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\Account\Account withoutTrashed()
* @mixin \Eloquent
*/
class Account extends Model implements AuthenticatableContract, JWTSubject
{
use NodeTrait, SoftDeletes, HasRoles, Authenticatable;
protected $table = 'accounts';
protected $fillable = ['id', 'username', 'nickname', 'email', 'mobile', 'password', 'salt', 'status'];
public static function boot()
{
parent::boot();
static::saving(function ($model) {
unset($model['avatar']);
});
}
/**
* Get the hidden attributes for the model.
*
* @return array
*/
public function getHidden()
{
return [$this->getLftName(), $this->getRgtName(), 'password', 'salt', 'deleted_at'];
}
/**
* 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 [];
}
}