Skip to content
Merged
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
26 changes: 26 additions & 0 deletions src/Filterable/Providers/FilterableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Filterable\Providers;

use Filterable\Console\MakeFilterCommand;
use Illuminate\Http\Request;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand All @@ -18,6 +19,31 @@ public function configurePackage(Package $package): void
->hasCommand(MakeFilterCommand::class);
}

/**
* {@inheritdoc}
*/
public function packageRegistered(): void
{
$this->registerFilterBindings();
}

/**
* Register global bindings for Filter dependencies.
*
* This ensures that when a Filter subclass is resolved from the DI container,
* it receives the current HTTP request instance rather than an empty Request.
*/
Comment on lines +30 to +35

Copilot AI Dec 4, 2025

Copy link

Choose a reason for hiding this comment

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

The docblock says "Register contextual bindings for Filter classes" but the implementation uses a global binding with bindIf(), not a contextual binding. Contextual bindings in Laravel use $this->app->when(SomeClass::class)->needs(...), while this is a global binding. Consider updating the docblock to:

/**
 * Register global bindings for Filter dependencies.
 *
 * This ensures that when a Filter subclass is resolved from the DI container,
 * it receives the current HTTP request instance rather than an empty Request.
 */

Copilot uses AI. Check for mistakes.
protected function registerFilterBindings(): void
{
// Bind Request class to resolve to the current request from the container.
// This ensures Filter subclasses get the active HTTP request instead of an empty one.
// Using bindIf() ensures we don't override any existing Request bindings.
// Tests can still override this by calling $app->instance(Request::class, $request).
$this->app->bindIf(Request::class, function ($app) {
return $app['request'];
});
}

/**
* {@inheritdoc}
*/
Expand Down
Loading
Loading