public function scopeWithAllWidgets(Builder $query, $widgets, string $column = 'id'): Builder
    {
        $widgets = static::isWidgetsStringBased($widgets)
            ? $widgets : static::hydrateWidgets($widgets)->pluck($column);

        collect($widgets)->each(function ($widget) use ($query, $column) {
            $query->whereHas('widgets', function (Builder $query) use ($widget, $column) {
                return $query->where($column, $widget);
            });
        });

        return $query;
    }
public function scopeWithAllWidgets(Builder $query, $widgets, string $column = 'id'): Builder
    {
        $widgets = static::isWidgetsStringBased($widgets)
            ? $widgets : static::hydrateWidgets($widgets)->pluck($column);

        collect($widgets)->each(function ($widget) use ($query, $column) {
            $query->whereHas('widgets', function (Builder $query) use ($widget, $column) {
                return $query->where($column, $widget);
            });
        });

        return $query;
    }
public function scopeWithAllWidgets ( Builder $ query , $ widgets , string $ column = 'id' ) : Builder { $ widgets = static :: isWidgetsStringBased ( $ widgets ) ? $ widgets : static :: hydrateWidgets ( $ widgets ) -> pluck ( $ column ) ; collect ( $ widgets ) -> each ( function ( $ widget ) use ( $ query , $ column ) { $ query -> whereHas ( 'widgets' , function ( Builder $ query ) use ( $ widget , $ column ) { return $ query -> where ( $ column , $ widget ) ; } ) ; } ) ; return $ query ; }
Scope query with all the given widgets.

@param \Illuminate\Database\Eloquent\Builder $query
@param int|string|array|\ArrayAccess|WidgetModelContract $widgets
@param string $column

@return \Illuminate\Database\Eloquent\Builder
Scope query with all the given widgets .