hjchin
hjchin

Reputation: 874

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.

Upvotes: 5

Views: 17284

Answers (1)

Jed
Jed

Reputation: 216

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

Upvotes: 4

Related Questions