Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions packages/admin/src/Support/Pages/BaseListRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ protected function applySearchToTableQuery(Builder $query): Builder
$scoutEnabled &&
$isScoutSearchable
) {
$ids = collect(static::getModel()::search($search)->take(100)->keys())->map(
fn ($result) => str_replace(static::getModel().'::', '', $result)
);
$trashedFilter = collect($this->getTable()->getFilters())
->firstWhere(fn ($filter) => $filter instanceof \Filament\Tables\Filters\TrashedFilter);
Comment on lines +35 to +36
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TrashedFilter class should be imported at the top of the file rather than using the fully qualified class name inline. This improves code readability and follows PHP best practices.

Copilot uses AI. Check for mistakes.

$placeholders = implode(',', array_fill(0, count($ids), '?'));
$scoutQuery = static::getModel()::search($search);

$query->whereIn(
'id',
$ids
);
if (filled($state = $trashedFilter?->getState()['value'] ?? null)) {
$state ? $scoutQuery->withTrashed() : $scoutQuery->onlyTrashed();
Comment on lines +40 to +41
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ternary logic is inverted. When $state is truthy (typically true), it should call withTrashed(), but when $state is falsy (typically false), it should call onlyTrashed(). However, this doesn't align with typical trashed filter conventions where true means 'with trashed' and false means 'only trashed'. This logic should be verified against the actual TrashedFilter state values to ensure correct behavior.

Suggested change
if (filled($state = $trashedFilter?->getState()['value'] ?? null)) {
$state ? $scoutQuery->withTrashed() : $scoutQuery->onlyTrashed();
$state = $trashedFilter?->getState()['value'] ?? null;
if ($state === 'with') {
$scoutQuery->withTrashed();
} elseif ($state === 'only') {
$scoutQuery->onlyTrashed();

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bot is wrong, just like previous coderabbit review

}

$query->when(
! $ids->isEmpty(),
fn ($query) => $query->orderBySequence($ids->toArray())
$ids = collect($scoutQuery->take(100)->keys())->map(
fn ($result) => str_replace(static::getModel().'::', '', $result)
);

$query
->whereIn('id', $ids)
->orderBySequence($ids);
}

return $query;
Expand Down
15 changes: 3 additions & 12 deletions packages/admin/src/Support/Resources/BaseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,9 @@ protected static function applyGlobalSearchAttributeConstraints(Builder $query,
fn ($result) => str_replace(static::getModel().'::', '', $result)
);

$placeholders = implode(',', array_fill(0, count($ids), '?'));

$query->whereIn(
'id',
$ids
);

$query->when(
! $ids->isEmpty(),
fn ($query) => $query->orderBySequence($ids->toArray())
);

$query
->whereIn('id', $ids)
->orderBySequence($ids);
} else {
/** @var Connection $databaseConnection */
$databaseConnection = $query->getConnection();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/LunarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ protected function registerObservers(): void

protected function registerBuilderMacros(): void
{
Builder::macro('orderBySequence', function (array $ids) {
Builder::macro('orderBySequence', function (iterable $ids) {
/** @var Builder $this */
$driver = $this->getConnection()->getDriverName();

if (empty($ids)) {
if (blank($ids)) {
return $this;
}

Expand Down
Loading