TorchSK said:
Why are you using auth()? If you use Auth::user()->id , does it work?
It doesn't work with Auth::user() also (same error). What's wrong with auth()? I thought it was helper class.
In case someone stumbles upon this thread. I managed to cheat a bit. What I did is saved authenticated user id in session in LoginListener handle method:
// LoginListener.php
public function handle(Login $event) {
session(['auth_user_id' => $event->user->id]);
}
And then in User model global scope used this value.
// User.php
protected static function boot() {
parent::boot();
if (session('auth_user_id')) {
static::addGlobalScope('test', function(Builder $builder) {
$builder->where('id', session('auth_user_id'));
});
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community