Planificacion y avances de backend

This commit is contained in:
2021-04-29 01:59:08 -04:00
parent 6e4076cf15
commit b6ea4a7ce2
21 changed files with 486 additions and 156 deletions

View File

@@ -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'] : [];
}
}