Loxxer
Loxxer
FFilament
Created by Loxxer on 2/26/2024 in #❓┊help
How to disable scopes for related model?
I can't get it to work. I'm building a table in ProductResource using
public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(fn (Builder $query) => $query->withoutGlobalScopes())
->recordClasses(fn (Model $record) => match ($record->local_status) {
'hidden' => 'opacity-50',
default => null,
})
->recordClasses(fn (Model $record) => match ($record->operation_status) {
'discontinued' => 'opacity-50', //grayscale
default => null,
})
->columns([
Tables\Columns\TextColumn::make('id')
->sortable()
->searchable()
->copyable()

Tables\Columns\ImageColumn::make('brand.icon')
->size(20)
->label('Brand')

])
...
}

public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(fn (Builder $query) => $query->withoutGlobalScopes())
->recordClasses(fn (Model $record) => match ($record->local_status) {
'hidden' => 'opacity-50',
default => null,
})
->recordClasses(fn (Model $record) => match ($record->operation_status) {
'discontinued' => 'opacity-50', //grayscale
default => null,
})
->columns([
Tables\Columns\TextColumn::make('id')
->sortable()
->searchable()
->copyable()

Tables\Columns\ImageColumn::make('brand.icon')
->size(20)
->label('Brand')

])
...
}


I've deactivated global sopes using modifyQueryUsing(), but this only works for the global scopes for the 'Product' model. As you can see, I am creating an ImageColumn from the related model 'Brand'. How can I disable global scopes for this relation? Right now, it's only creating an ImageColumn for scoped brands, but I need images for all brands, independent of the global scopes of the 'Brand' model. How can I managecan I manage this?
3 replies