-
-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route Model Binding Exception #4108
Comments
Slugs are not unique anymore, not sure the best way to handle this |
It works when simply removing the part that throws the error. But I'm not sure if it breaks something else. |
It assumes the collection is in the route too. Just rename your route parameter to avoid using route model binding.
|
But I want to use route model binding. What I'm after is creating a route that gets the full context like a regular collection entry does. Not sure if I'm understanding route model binding correctly. This works. I see that the Route::statamic('/test/{collection}/{entry}', 'my_test_view'); I also tried to use a controller like mentioned in the docs. But this throws an Route::statamic('/test/{collection}/{entry}', [TestController::class, 'show']); class TestController extends Controller
{
public function show($collection, $entry)
{
dd($collection, $entry);
}
} |
Not entirely sure if this is totally related to this issue but we're coming up against a couple issues regarding route model binding when installing Statamic into an existing Laravel application. (I'm happy to move this to a fresh issue if that's better) In our case we have an Eloquent model called This is the error we're seeing with any of the routes with {
"message": "Call to a member function handle() on null",
"exception": "Error",
"file": "/home/the-project-in-question/vendor/statamic/cms/src/Providers/RouteServiceProvider.php",
"line": 111,
} In Statamic's We can potentially work around this by overriding the route-model binding ourselves and doing a check if the request is from the CP or not. If it is, we use Statamic's stuff, if not we bind to our own $firstPath = explode('/', request()->getPathInfo())[1];
if ($firstPath === 'cp') {
return $assetId;
} This obviously isn't ideal - maybe Statamic could prefix it's bindings with Using Statamic alongside existing Laravel applications are our primary use case - in fact, this is the third app that we're doing it on. |
Honestly I think we should remove our bindings. As you can see it conflicts with people's applications too much. We already removed one here #3088 |
I just bumped into the same issue installing onto an existing Laravel app - |
Bug Description
Route Model Binding as described here doesn't work. It throws a
Call to a member function id() on null
Exception.The issue is
$route->parameter('collection')->id()
. The parametercollection
does not exist.cms/src/Providers/RouteServiceProvider.php
Line 61 in c58e7b4
How to Reproduce
Add this route and a test view:
Environment
Statamic 3.1.32 Pro
Laravel 8.53.1
PHP 7.4.20
The text was updated successfully, but these errors were encountered: