我有 2 个 Controller 函数,它们调用位于应用程序文件夹下的类的静态函数。
Controller \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);
}
应用\用户.php
public static function show($id, Request $request){
//codes
}
让我感到惊讶的是,这些代码在开发和暂存环境中运行正常,但在生产环境中却不行。
它抛出异常 'Symfony\Component\Debug\Exception\FatalErrorException' 和消息 'Call to undefined method App\User::show()'
是什么原因造成的?谢谢。
最佳答案
可能是生产环境使用的是较旧的缓存或编译版本。当发生这种情况时,我总是尝试:
composer update
或者
composer dump-autoload
或者
php artisan clear-compiled
或者
php artisan cache:clear
关于php - Laravel "Call to undefined method"仅在生产中发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45474010/