1

我想在全局范围内使用 Auth 用户

用户.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();
            }  
        });
 }

我无法在范围内获取身份验证用户,因为范围在身份验证后被提前调用,是否可以在全局范围内获取身份验证用户?

4

0 回答 0