Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel ClassLoader trying to load an old version of my model

Tags:

laravel

model

So a while back I decided to redo one of my models in Laravel completely, but I wanted to hold on to the original copy of the file just in case. So I renamed it to something like MyModel (OLD).php and left it there in the models folder next to the new model.

Now that I understand Laravel a bit better, I realize that wasn't a great idea, but in any case everything seemed to work for months. Then today, I made a minor update (modifying a database query) to one of the functions in my new model and suddenly Laravel is trying to load the old copy of my model. I finally moved the old copy out of the models folder and into a backup folder completely outside of my laravel application, but now Laravel throws the error:

include(pathToMyModels/MyModel (OLD).php): failed to open stream: No such file or directory

referring to this section of ClassLoader.php

/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

I tried undoing the modification to the model, changing the route and controller function name, clearing laravel's cache, clearing the browser cache, using different browsers, but nothing seems to work except to manually include the model's php file before calling the class it contains. What can I do to get Laravel to automatically recognize my model like it does all the others I have?

like image 411
Chris Avatar asked May 18 '14 18:05

Chris


2 Answers

Try to clear composer cache and then run composer dump-autoload.

composer clear-cache
composer dump-autoload
like image 196
Chamin Wickramarathna Avatar answered Oct 14 '22 03:10

Chamin Wickramarathna


if you don't want to run commands then try this one, i think it's solve your problem.

  1. goto your laravel_project_folder\vendor\composer
  2. now open the file autoload_classmap.php and autoload_static.php in your text editor
  3. and find your old/backup file name line
  4. and rename with actual filename and correct their path.
  5. now run your project again and check for the error occurance, i think your problem is solved.
like image 4
Anjani Barnwal Avatar answered Oct 14 '22 02:10

Anjani Barnwal