Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this error with Laravel: PHP Catchable Fatal Error?

I'm getting this error when I try to run php artisan (anything):

PHP Catchable fatal error:  Argument 2 passed to
Illuminate\Routing\UrlGenerator::__construct()
must be an instance of Illuminate\Http\Request, null given, called in
/www/laravel5/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php
on line 56 and defined in
/www/laravel5/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php
on line 81

Catchable fatal error: Argument 2 passed to
Illuminate\Routing\UrlGenerator::__construct()
must be an instance of Illuminate\Http\Request, null given, called in
/www/laravel5/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php
on line 56 and defined in
/www/laravel5/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php
on line 81

I have absolutely no idea what is causing it and need help with it.

Thanks in advance

like image 935
Mathius17 Avatar asked Feb 18 '15 04:02

Mathius17


2 Answers

Well I discovered what generated the error.

In config/services.php I was doing this:

'facebook' => [
    'client_id'     => env('FACEBOOK_APP_ID', null),
    'client_secret' => env('FACEBOOK_APP_SECRET', null),
    'redirect'      => url('auth/facebook'),
]

url('auth/facebook') is what caused the error.

like image 119
Mathius17 Avatar answered Oct 09 '22 09:10

Mathius17


As you figured out, the problem is caused by using url() in config. The same would happen if you used asset(). When running artisan commands, the framework can't figure out what the website url is, hence the error.

I just want to propose an alternative solution:

'facebook' => [
  'client_id'     => '***'
  'client_secret' => '***',
  'redirect'      => PHP_SAPI === 'cli' ? false : url('/fb-callback-path'),
]

I don't love it but it's very unlikely you're ever going to need your FB redirects when running command line scripts and this way you don't have to remember about configuring the redirect in each environemnt.

like image 40
Rafał G. Avatar answered Oct 09 '22 09:10

Rafał G.