83 lines
2.0 KiB
PHP
83 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models\WebService;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Tymon\JWTAuth\Contracts\JWTSubject;
|
|
|
|
class Usuario extends Authenticatable implements JWTSubject
|
|
{
|
|
protected $table = 'web_service_usuario';
|
|
|
|
protected $fillable = [
|
|
'nome',
|
|
'usuario',
|
|
'senha',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'senha',
|
|
'created_at',
|
|
'created_lotacao_id',
|
|
'created_centro_custo_id',
|
|
'updated_at',
|
|
'updated_lotacao_id',
|
|
'updated_centro_custo_id',
|
|
];
|
|
|
|
public function setSenhaAttribute($value)
|
|
{
|
|
$this->attributes['senha'] = Hash::make($value);
|
|
}
|
|
|
|
public function permissoes()
|
|
{
|
|
return $this->belongsToMany(Permissao::class, 'web_service_usuario_permissao', 'usuario_id', 'permissao_id')
|
|
->using(UsuarioPermissao::class)
|
|
->as('pivotUsuarioPermissao')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function logsAcessos()
|
|
{
|
|
return $this->hasMany(LogAcesso::class);
|
|
}
|
|
|
|
public function getJWTIdentifier()
|
|
{
|
|
return $this->getKey();
|
|
}
|
|
|
|
public function getJWTCustomClaims()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function ($model) {
|
|
|
|
if (auth()->check()) {
|
|
|
|
$model->created_lotacao_id = auth()->payload()->get('lotacao_id');
|
|
$model->created_centro_custo_id = auth()->payload()->get('centro_custo_id');
|
|
|
|
$model->updated_lotacao_id = auth()->payload()->get('lotacao_id');
|
|
$model->updated_centro_custo_id = auth()->payload()->get('centro_custo_id');
|
|
}
|
|
});
|
|
|
|
static::updating(function ($model) {
|
|
|
|
if (auth()->check()) {
|
|
|
|
$model->updated_lotacao_id = auth()->payload()->get('lotacao_id');
|
|
$model->updated_centro_custo_id = auth()->payload()->get('centro_custo_id');
|
|
}
|
|
});
|
|
}
|
|
}
|