Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

574
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!