dsxrq28228
2017-08-03 02:51
浏览 398
已采纳

Laravel“调用未定义的方法”,仅在生产中发生

I have 2 controller functions which call a static function of a class located right under app folder.

Controllers\UserResController.php

public function show($id, Request $request)
{
   return \App\User::show($id, $request);
}

Conrtollers\Other\UserResController.php

public function show($id, Request $request)
{
   // other codes

   return \App\User::show($id, $request);
}

app\User.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()'

What causes it? Thanks.

图片转代码服务由CSDN问答提供 功能建议

我有2个控制器函数,它们调用位于app文件夹下的类的静态函数。

Controllers \ UserResController.php

 公共函数show($ id,Request $ request)
 {
 return \ App \  User :: show($ id,$ request); 
} 
   
 
 

Conrtollers \ Other \ UserResController.php

  公共函数show($ id,Request $ request)
 {
 //其他代码
 
返回\ App \ User :: show($ id,$ request); 
} 
   
 
 

app \ User.php

  public static function show($ id,Request $ request){
 // code  
} 
   
 
 

让我感到惊讶的是,这些代码在开发和登台环境中运行正常但在生产环境中运行不正常。

它抛出异常'Symfony \ Component \ Debug \ Exception \ FatalErrorException',并显示消息'调用未定义的方法App \ User :: show()'

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsfg3241 2017-08-03 03:00
    已采纳

    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
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题