I am use OctoberCMS Rainlab.User plugin to manage authentication.
I have various models and that belongTo User.
How do i set up an anonymous global scope on each model to only return the records that belong to the authenticated user?
Many thanks in advance for any help.
use Auth;
protected static function booted()
{
$user = Auth::getUser();
static::addGlobalScope('user_id', function (Builder $builder){
$builder->where('user_id', $user);
});
}