Mas validaciones
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user