This commit is contained in:
82
api/app/Models/WebService/Usuario.php
Normal file
82
api/app/Models/WebService/Usuario.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user