diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index f58bd7db..34d20859 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -244,8 +244,8 @@ protected function bootPermissions(): self protected function bootRouteBindings(): self { Route::bind('discount', function ($handle, $route = null) { - if (! $route || ! $this->isCpRoute($route)) { - return false; + if (! $route || (! $this->isCpRoute($route) && ! $this->isFrontendBindingEnabled())) { + return $handle; } $field = $route->bindingFieldFor('discount') ?? 'handle'; @@ -256,8 +256,8 @@ protected function bootRouteBindings(): self }); Route::bind('order', function ($id, $route = null) { - if (! $route || ! $this->isCpRoute($route)) { - return false; + if (! $route || (! $this->isCpRoute($route) && ! $this->isFrontendBindingEnabled())) { + return $handle; } $field = $route->bindingFieldFor('order') ?? 'id'; @@ -268,16 +268,16 @@ protected function bootRouteBindings(): self }); Route::bind('tax-class', function ($handle, $route = null) { - if (! $route || ! $this->isCpRoute($route)) { - return false; + if (! $route || (! $this->isCpRoute($route) && ! $this->isFrontendBindingEnabled())) { + return $handle; } return TaxClass::find($handle); }); Route::bind('tax-zone', function ($handle, $route = null) { - if (! $route || ! $this->isCpRoute($route)) { - return false; + if (! $route || (! $this->isCpRoute($route) && ! $this->isFrontendBindingEnabled())) { + return $handle; } return TaxZone::find($handle); @@ -286,7 +286,7 @@ protected function bootRouteBindings(): self return $this; } - protected function isCpRoute(\Illuminate\Routing\Route $route) + private function isCpRoute(\Illuminate\Routing\Route $route): bool { $cp = \Statamic\Support\Str::ensureRight(config('statamic.cp.route'), '/'); @@ -297,6 +297,11 @@ protected function isCpRoute(\Illuminate\Routing\Route $route) return Str::startsWith($route->uri(), $cp); } + private function isFrontendBindingEnabled(): bool + { + return config('statamic.routes.bindings', false); + } + protected function bootGit(): self { if (config('statamic.git.enabled')) {