src/Eloquent/OptionalTenantableScope.php
/**
     * Apply the scope to a given Eloquent query builder.
     *
     * @param  \Illuminate\Database\Eloquent\Builder $builder
     * @param  \Illuminate\Database\Eloquent\Model   $model
     * @return void
     */
Apply the scope to a given Eloquent query builder.
Apply the scope to a given Eloquent query builder .
protected function handle(EloquentBuilder $builder, Model $model)
    {
        return $builder->where(
            function ($advanced) use ($model) {
                $tenantForeignKey = $model->qualifyColumn(config('tenant.foreign_key'));
                return $advanced->whereNull($tenantForeignKey)->orWhereHas(
                    'tenant', function ($tenant) {
                        $tenant->whereKey($this->tenant()->getKey());
                    }
                );
            }
        );
    }
protected function handle ( EloquentBuilder $ builder , Model $ model ) { return $ builder -> where ( function ( $ advanced ) use ( $ model ) { $ tenantForeignKey = $ model -> qualifyColumn ( config ( 'tenant.foreign_key' ) ) ; return $ advanced -> whereNull ( $ tenantForeignKey ) -> orWhereHas ( 'tenant' , function ( $ tenant ) { $ tenant -> whereKey ( $ this -> tenant ( ) -> getKey ( ) ) ; } ) ; } ) ; }
Apply the scope to a given Eloquent query builder.
Apply the scope to a given Eloquent query builder .
// modelField is null // build query