Mas validaciones

This commit is contained in:
2021-07-20 23:55:49 -04:00
parent 1d6082a590
commit 738860296c
8 changed files with 59 additions and 47 deletions

View File

@@ -49,6 +49,23 @@ class Usuario extends Model {
return $this->restaurantes()->where('id', $restaurante->id)->count() > 0;
}
public function isColega($usuario) {
return $this->colegas()->contains($usuario);
}
public function colegas() {
if($this->isGlobalAdmin()) return Usuario::all();
$restaurantes = $this->restaurantes;
$colegas = collect([]);
foreach($restaurantes as $restaurant) {
$colegas = $colegas->merge($restaurant->usuarios);
}
return $colegas->unique('id');
}
public function restaurantes() {
return $this->belongsToMany(Restaurante::class, 'usuarios_restaurantes', 'usuario_id', 'restaurante_id');
}