Skip to content

Fix BindingResolutionException when injecting ResourceType into custom route controllers - #170

Draft
arietimmerman with Copilot wants to merge 6 commits into
masterfrom
copilot/fix-general-error-issue
Draft

Fix BindingResolutionException when injecting ResourceType into custom route controllers#170
arietimmerman with Copilot wants to merge 6 commits into
masterfrom
copilot/fix-general-error-issue

Conversation

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

When users define custom routes with ResourceType $resourceType type-hinted in controller methods, Laravel's IoC container fails to instantiate ResourceType directly because its constructor requires $name and $configuration. The existing route model binding ($router->bind('resourceType', ...)) only fires when SubstituteBindings middleware is active, leaving the container with no way to resolve it otherwise.

Changes

  • ServiceProvider::register() — adds a scoped() container binding for ResourceType that resolves from the current route's resourceType parameter:
    • Returns the parameter as-is if it's already a ResourceType instance (i.e. SubstituteBindings already ran)
    • Builds a fresh ResourceType from SCIM config when the parameter is still a string
    • Guards against non-HTTP contexts (console, queue) via instanceof Illuminate\Http\Request check before accessing the route
    • Throws a descriptive BindingResolutionException when no resourceType route parameter is present

Using scoped() ensures one instance per request lifecycle (Octane-safe).

// Custom controller — now resolves correctly with or without SubstituteBindings
public function index(Request $request, PolicyDecisionPoint $pdp, ResourceType $resourceType)
{
    // $resourceType is correctly resolved from the {resourceType} route parameter
}

Copilot AI linked an issue Jul 23, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix general error with custom class reference Fix BindingResolutionException when injecting ResourceType into custom route controllers Jul 23, 2026
Copilot AI requested a review from arietimmerman July 23, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

General error?

2 participants