Laravel“调用未定义的方法”只发生在生产中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45474010/
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
Laravel "Call to undefined method" which only happens in production
提问by hjchin
I have 2 controller functions which call a static function of a class located right under app folder.
我有 2 个控制器函数,它们调用位于 app 文件夹下的类的静态函数。
Controllers\UserResController.php
控制器\UserResController.php
public function show($id, Request $request)
{
return \App\User::show($id, $request);
}
Conrtollers\Other\UserResController.php
控制器\其他\UserResController.php
public function show($id, Request $request)
{
// other codes
return \App\User::show($id, $request);
}
app\User.php
应用程序\用户.php
public static function show($id, Request $request){
//codes
}
What surprised me is that these code run OK in development and staging environment but not in production.
令我惊讶的是,这些代码在开发和登台环境中运行良好,但在生产环境中却没有。
It throws exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method App\User::show()'
它抛出异常 'Symfony\Component\Debug\Exception\FatalErrorException' 并带有消息 'Call to undefined method App\User::show()'
What causes it? Thanks.
是什么原因造成的?谢谢。
采纳答案by Jed
Chances are the production environment is using an older cached or compiled version. When that happens, I always try:
生产环境可能正在使用较旧的缓存或编译版本。发生这种情况时,我总是尝试:
composer update
Or
或者
composer dump-autoload
Or
或者
php artisan clear-compiled
Or
或者
php artisan cache:clear