2

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?

Mdr Kuchhadiya
  • 431
  • 4
  • 12

0 Answers0