Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

575
Vistas
Laravel - How to use Auth user inside the global scope

I want to use Auth user in the global scope

User.php

 public function scopeActive($query)
 {
      return $query->where('accessed_id', auth()->user()->accessed_id);
 }

 protected static function boot()
 {
        parent::boot();    
        static::addGlobalScope('customer_user', function (Builder $builder) {
            if(auth()->check()){  // check user is auth or not
                 $builder->active();
            }  
        });
 }

I am unable to get auth user in scope because the scope was early called then after authentication, It's possible to get auth user in the global scope?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda