Planificacion y avances de backend
This commit is contained in:
@@ -2,16 +2,53 @@
|
||||
|
||||
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'] : [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user