What do your controller methods look like?
Because this should work (as long as you have all the parameters in the controller methods setup correctly)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Maybe it's really simple (like many things in laravel), but I do not see right way:
I want group some controller functions. Now, there can be different group names but the controllers are always the same. In my example groups can be "project" or "documentation" with the controllers for "event" and "details". Any other non existing group name should throw an error for a non existing route. A working code is that:
Route::get('{projectType}/event', 'MyEventController@index')->where('projectType', 'project|documentation');
Route::get('{projectType}/details', 'MyDetailsController@index')->where('projectType', 'project|documentation');
Now, that code isn't really pretty and when the controller lists grows, it is harder to maintain and understand. So i try:
Route::prefix('{projectType}')->group(function () {
Route::get('event', 'MyEventController@index');
Route::get('details', 'MyDetailsController@index');
})->where('projectType', 'project|documentation');
but this throws only an error "Call to a member function where() on null". It looks like prefix doesn't support what i want?
How to solve?
Aah, I figured it might have been from the controller part.....
Here's a working example, just switch the group and the where() around
Route::prefix('{projectType}')
->where(['projectType' => 'project|documentation'])->group(function () {
Route::get('event', function($projectType) {
dd($projectType);
});
Route::get('details', function($projectType) {
dd($projectType);
});
});
// so in your case:
Route::prefix('{projectType}')
->where(['projectType' => 'project|documentation'])->group(function () {
Route::get('event', 'MyEventController@index');
Route::get('details', 'MyDetailsController@index');
});
And make sure both Controllers have the $projectType as their first parameter and make sure the where() method gets an array, not 2 strings.
Please or to participate in this conversation.