Example of Global scopes in mohsin-shaikh/expense-tracker

File app/Scopes/UserVisibilityScope.php (link to Github)
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Support\Facades\Auth;

final class UserVisibilityScope implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        $builder->where('user_id', Auth::id());
    }
}
File app/Models/Category.php (link to Github)
use App\Scopes\UserVisibilityScope;
use Illuminate\Database\Eloquent\Model;

final class Category extends Model
{
    //
    protected static function booted(): void
    {
        static::addGlobalScope(new UserVisibilityScope());
    }
    //
}

Additional resources on global scopes: