55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\Auth0Service;
|
|
use App\Traits\UuidPrimaryKey;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Class Usuario
|
|
*
|
|
* @property $id
|
|
* @property $auth0_id
|
|
* @property $nombre
|
|
*
|
|
* @method static find($id)
|
|
* @method static where(string $string, $sub)
|
|
*
|
|
* @package App\Models
|
|
*
|
|
*/
|
|
class Usuario extends Model {
|
|
use UuidPrimaryKey, SoftDeletes;
|
|
|
|
protected $table = 'usuarios';
|
|
protected $appends = ['roles'];
|
|
|
|
public function restaurantes() {
|
|
return $this->belongsToMany(Restaurante::class, 'usuarios_restaurantes', 'usuario_id', 'restaurante_id');
|
|
}
|
|
|
|
public function administrador() {
|
|
return $this->hasOne(Administrador::class);
|
|
}
|
|
|
|
public function recaudador() {
|
|
return $this->hasOne(Recaudador::class);
|
|
}
|
|
|
|
public function mesero() {
|
|
return $this->hasOne(Mesero::class);
|
|
}
|
|
|
|
public function productor() {
|
|
return $this->hasOne(Productor::class);
|
|
}
|
|
|
|
public function getRolesAttribute() {
|
|
$auth0Service = app(Auth0Service::class);
|
|
$auth0User = $auth0Service->getUser($this->auth0_id);
|
|
return $this->attributes['roles'] = array_key_exists('app_metadata', $auth0User) ? $auth0User['app_metadata']['roles'] : [];
|
|
}
|
|
}
|