Laravel ClassLoader 试图加载我的模型的旧版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23725610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel ClassLoader trying to load an old version of my model
提问by Chris
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.
所以不久前我决定在 Laravel 中完全重做我的一个模型,但我想保留文件的原始副本以防万一。因此,我将其重命名为 MyModel (OLD).php 之类的内容,并将其留在新模型旁边的模型文件夹中。
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:
现在我对 Laravel 有了更好的理解,我意识到这不是一个好主意,但无论如何,几个月来一切似乎都有效。然后今天,我对我的新模型中的一个函数做了一个小更新(修改数据库查询),突然 Laravel 试图加载我的模型的旧副本。我终于将旧副本从模型文件夹中移到了我的 Laravel 应用程序之外的备份文件夹中,但现在 Laravel 抛出错误:
include(pathToMyModels/MyModel (OLD).php): failed to open stream: No such file or directory
referring to this section of ClassLoader.php
参考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?
我尝试撤消对模型的修改,更改路由和控制器函数名称,清除 Laravel 的缓存,清除浏览器缓存,使用不同的浏览器,但除了在调用它包含的类之前手动包含模型的 php 文件外,似乎没有任何效果。我该怎么做才能让 Laravel 自动识别我的模型,就像我拥有的所有其他模型一样?
回答by Chamin Wickramarathna
Try to clear composer cache and then run composer dump-autoload.
尝试清除 composer 缓存,然后运行 composer dump-autoload。
composer clear-cache
composer dump-autoload
回答by Anjani Barnwal
if you don't want to run commands then try this one, i think it's solve your problem.
如果您不想运行命令,请尝试这个,我认为它可以解决您的问题。
- goto your laravel_project_folder\vendor\composer
- now open the file autoload_classmap.php and autoload_static.php in your text editor
- and find your old/backup file name line
- and rename with actual filename and correct their path.
- now run your project again and check for the error occurance, i think your problem is solved.
- 转到你的 laravel_project_folder\vendor\composer
- 现在在文本编辑器中打开文件 autoload_classmap.php 和 autoload_static.php
- 并找到您的旧/备份文件名行
- 并使用实际文件名重命名并更正它们的路径。
- 现在再次运行您的项目并检查是否发生错误,我认为您的问题已解决。
回答by david valentino
i just knew that my laravel using old controller after 1 hour of debuging. what time waste
我只知道我的 laravel 在调试 1 小时后使用旧控制器。浪费什么时间
i tried accepted answer but still persist
我试过接受的答案,但仍然坚持
i delete the controller and recreate, now works
我删除了控制器并重新创建,现在可以工作了
- copy all the code
- delete the controller
- make http request to that controller (404)
- create file same name
- paste in
- 复制所有代码
- 删除控制器
- 向该控制器发出 http 请求 (404)
- 创建同名文件
- 粘贴