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

nitish's avatar

Cannot run php artisan

Hi, I get the following error when I run 'php artisan'. Could anyone please help in locating the source of this error?

PHP Catchable fatal error:  Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in /home/abeir/code/projects/testproject/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 56 and defined in /home/abeir/code/projects/testproject/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 81
0 likes
29 replies
bobbybouwmann's avatar

I had this error before, it was because I misspelled something in my routes.php.

Make sure you have done this:

  • Check that the Kernel is binded using the correct namespace in bootstrap/app.php.
  • After, check that your composer.json app namespace is correct.
  • Finally, run composer dump-autoload.
1 like
Rtransat's avatar

@mstnorris

<?php

Route::group(
    [
        'prefix' => LaravelLocalization::setLocale(),
        'middleware' => [ 'localizationRedirect', 'localize' ]
    ], function()
{
    Route::get( '/', ['as' => 'home', 'uses' => 'PagesController@index']);
    Route::get( LaravelLocalization::transRoute('routes.cursus'), 'PagesController@cursus' );
    Route::get( LaravelLocalization::transRoute('routes.eco'), 'PagesController@eco' );
});

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

Route::group([ 'prefix' => 'admin'], function()
{
    Route::get('/', [
        'as' => 'admin.home',
        'uses' => 'FlipbookController@index'
    ]);

    Route::resource('flipbook', 'FlipbookController');
});

I've also tried this :

<?php

Route::get( '/', ['as' => 'home', 'uses' => 'PagesController@index']);

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

Route::group([ 'prefix' => 'admin'], function()
{
    Route::get('/', [
        'as' => 'admin.home',
        'uses' => 'FlipbookController@index'
    ]);

    Route::resource('flipbook', 'FlipbookController');
});
sanjay23's avatar

I am also facing this issue in my project. Is anyone having a proper solution to get rid on this.

Thanks in advance

slashadmin's avatar

I had the same problem and found a solution. The problem was, that I used the url() and asset() Helper functions within configuration files. After removing them artisan started worked again.

62 likes
avidenov's avatar

I had the same problem, when using the ktquez/laravel-tinymce it generated a config file which have inside

'cdn' => url('vendor/js/tinymce/tinymce.min.js'),

Changing it to

'cdn' => Config('app.url').'/vendor/js/tinymce/tinymce.min.js',

did the trick, but I'm not sure if this is a good idea. Any suggestions?

20 likes
dangelsaurus's avatar

url() in my services.php file caused the problem for me as well. should this be submitted as a bug?

4 likes
cent040's avatar

The problem was, that I used the url() and asset() Helper functions within configuration files. After removing them artisan started worked again. Thanks @slashadmin

6 likes
inilabs's avatar

@nitish i think you used url() helper in your any config file in config folder, i had this same problem.

1 like
jorenvh's avatar

I had the same problem. How did you guys retrieve the paths in these files?

joaomantovani's avatar

The solution of the cent040 did the trick to me.

The problem was:

I've defined the paths to do a backup with the asset()

'include' => [
    asset('home'),
    asset('images'),
    asset('uploads'),
],

and when I changed to the base_path(), It worked perfectly.

'include' => [
    base_path('public/home'),
    base_path('public/images'),
    base_path('public/uploads'),
],
3 likes
EmilMoe's avatar

Thanks. You can also just use public_path()

1 like
Awais_Jameel's avatar

I my case url() helper function in my filesystem.php is causing the issue. I removed it and every thing works fine.

spiCkyyy's avatar

Brothers, I'm facing this error: [Symfony\Component\Debug\Exception\FatalThrowableError] Type error: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\H ttp\Request, null given, called in E:\programming\proc\vendor\laravel\framework\src\Illuminate\Routing\RoutingServi ceProvider.php on line 64

Does anyone have any idea about this?

Shahrukh4's avatar

I figured out the problem, when you are running any artisan command you should avoid using helper functions in any of your config files. Just comment those and try to run artisan command after running that uncomment your config files.

//*in config/'any_file.php'*
return [
    'name'  => 'Larvel',
    'url'       => url('/')
];

//*just change and uncomment url() helper*
return [
    'name'  => 'Larvel',
    //'url' => url('/')
];
1 like
gnela's avatar

Same error:

In UrlGenerator.php line 120:                
  Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given [...]

Thanks to @slashadmin: I had a custom configuration in my config/filesystem.php:

'public_uploads' => [
            'driver' => 'local',
            'root'   => public_path() . '/uploads',
            'url' => url('uploads'),
        ],

I removed 'url' => url('uploads'), and now it works. Strangely, i added these lines days ago and the error appears in console only now.

Thanks.

sojitra's avatar

I have the same problem plz help me... Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in C:\xampp\htdocs\golmarket\vendor\laravel\framework\src\Illuminate\Routing\RoutingServiceProv ider.php on line 62

TranDung's avatar

Hi there! did you solve it?? i have the same problem but i didn't find any way .. :((

Please or to participate in this conversation.