为什么我在Laravel中遇到此错误:PHP Catchable致命错误?

时间:2015-02-18 04:38:19

标签: php laravel runtime-error laravel-5

我尝试运行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

我完全不知道造成它的原因是什么,需要帮助。

提前致谢

3 个答案:

答案 0 :(得分:30)

好吧,我发现了产生错误的原因。

config/services.php我这样做:

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

url('auth/facebook')是造成错误的原因。

答案 1 :(得分:10)

正如您所知,问题是由在config中使用url()引起的。如果您使用asset(),也会发生同样的情况。在运行artisan命令时,框架无法弄清楚网站网址是什么,因此错误。

我只想提出另一种解决方案:

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

我不喜欢它但是在运行命令行脚本时你不太可能需要你的FB重定向,这样你就不必记得配置每个环境中的重定向。

答案 2 :(得分:0)

问题是由在config中使用url()引起的。 我从config / filesystems.php中删除了它,它工作了! 我希望能帮到你!

相关问题