Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

legalba13c's avatar

Laravel 12 require additional route files

In Laravel 8 it was possible to include additional route files with the require base_path parameter

//routes/web.php

Route::middleware(['web'])->group(function () { require base_path('routes/link/webhook.php'); });

php artisan route:cache responds that

Error: require(webhook): Failed to open stream: No such file or directory

This fails to work with require . DIR . '/link/webhook.php'; as well

Error: require(webhook): Failed to open stream: No such file or directory

The documentation recommends using the app.php function

// laravel.com/docs/12.x/routing - bootstrap/app.php

use Illuminate\Support\Facades\Route;

->withRouting(

web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
then: function () {
    Route::middleware('web')
        ->group(base_path('routes/link/webhooks.php'));
},

)

php artisan route:cache responds

Error: require(webhook): Failed to open stream: No such file or directory

an ls -s routes/link/webhook.php responds with the filename and I have already tried to chmod -R 777 routes and chown -R user:user routes

When the path is made incorrect it lists the entire incorrect path: require base_path('routeslink/webhook.php');

/var/www/html/laravel-project/routeslink/webhook.php cannot be found but when fixed it returns

Error: require(webhook): Failed to open stream: No such file or directory

I have also tried listing the route in the RouteServiceProvider by the same syntax but it still returns

Error: require(webhook): Failed to open stream: No such file or directory

If i remove all requires and changes to the bootstrap/app.php and RouteServiceProvider.php php artisan route:cache works well.

I have also tried to composer dump-autoload php artisan cache:clear

But the app is still unable to find the existing additional route file How can I fix this error?

0 likes
6 replies
Tray2's avatar

You got the path wrong.

Error: require(webhook): Failed to open stream: No such file or directory

legalba13c's avatar

@Tray2 Upon examination I see it is due to the use of ['namespace' => 'webhook'] in the laravel 12 groups first parameter group(['namespace' => 'webhook'], function(){}). The parameter usage is parsed differently. Any reccommendations on how to replace?

legalba13c's avatar

group(['namespace' => 'webhook'], function(){}). within the routes/link/webhook.php file. The file itself causes errors due to use of the namespace key value pair array in the groups first parameter

legalba13c's avatar

@Tray2 Answer: ->namespace('webhook') while removing the array in use from laravel 8, as it changes the path. This seems to apply for all other Laravel 8 conventions like ['group' => 'webhooks'] but I am still looking for the Laravel 12 equivalent to keys like 'group'

Tray2's avatar

The easiest is to use the base_path helper.

require base_path('routes/link/webhooks.php');
GdS's avatar

@legalba13c It looks like a path mismatch.

I am not sure that base_path() helper is working in bootstrap.php, have you tried using __DIR__?

I would avoid helper functions until the app is booted.

then: function () {
   Route::middleware('web')->group(__DIR__ . '/../routes/extra.php');
}

Hope it helps

Please or to participate in this conversation.