为什么我在使用 Laravel 时收到此错误:PHP Catchable Fatal Error?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28576088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:58:09  来源:igfitidea点击:

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

phplaravelruntime-errorlaravel-5

提问by Mathius17

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

当我尝试运行时出现此错误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

提前致谢

回答by Mathius17

Well I discovered what generated the error.

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

In config/services.phpI was doing this:

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')is what caused the error.

url('auth/facebook')是什么导致了错误。

回答by Rafa? G.

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.

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

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.

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

回答by Ngannv

The problem is caused by using url() in config. i removed it from config/filesystems.php and it worked! i hope help you!

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