Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel "Call to undefined method" which only happens in production

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.

like image 522
hjchin Avatar asked Oct 17 '22 08:10

hjchin


1 Answers

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
like image 97
Jed Avatar answered Oct 21 '22 08:10

Jed