找不到 laravel 类(适用于 localhost 但不适用于 DO 服务器)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22829998/
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 class not found (works on localhost but not on DO server)
提问by geoctrl
This is a repeat question - eg: Laravel 4 migrations - class not found
这是一个重复的问题 - 例如: Laravel 4 migrations - class not found
However, I've tried every solution (from every forum I could find) and cannot figure this out.
但是,我已经尝试了所有解决方案(从我能找到的每个论坛),但无法解决这个问题。
Scenario
设想
I created a Laravel 4 project on my local machine - added some classes, controllers, views, etc - the project works great.
我在本地机器上创建了一个 Laravel 4 项目——添加了一些类、控制器、视图等——该项目运行良好。
I then copy this fresh repo onto my DO server - install dependencies with composer, etc. The project looks good, except for one page that shouts an error:
然后我将这个新的 repo 复制到我的 DO 服务器上 - 使用 composer 安装依赖项等。该项目看起来不错,除了一个页面显示错误:
Class 'company' not found
Symfony\Component\Debug\Exception\FatalErrorException
…/-vendor/-laravel/-framework/-src/-Illuminate/-Database/-Eloquent/-Model.php593
You can view this page here.
您可以在此处查看此页面。
I've tried...
我试过了...
I've updated composer. I've tried "dump-autoload". I changed the 'minimum-stability' to 'stable' in the composer.json file (yes, this was a proposed solution on a forum post).
我已经更新了作曲家。我试过“转储自动加载”。我在 composer.json 文件中将 'minimum-stability' 更改为 'stable'(是的,这是在论坛帖子中提出的解决方案)。
Other solutions have to do with adding "psr-4" or "psr-0" into the composer.json file depending on the composer version - tried both.
其他解决方案与根据作曲家版本将“psr-4”或“psr-0”添加到 composer.json 文件有关 - 两者都尝试过。
What boggles my mind about this the most, is that this page works great on my local machine, but not on the DO server....If you guys need more info about something to fish this answer out, just let me know.
最让我感到困惑的是,这个页面在我的本地机器上运行良好,但在 DO 服务器上运行良好......如果你们需要更多关于某些东西的信息来找出这个答案,请告诉我。
Any help is appreciated :)
任何帮助表示赞赏:)
this is what my composer.json file looks like:
这是我的 composer.json 文件的样子:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.0.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
回答by The Alpha
Most probably (I'm pretty sure) your local environment is Windows
and live server is Linux
. So if the class company
class file is used as company.php
on local server then it's same Company.php
on local server but as Linux
follows case sensitive rules so it reads the company.php
and Company.php
as two different files.
最有可能(我很确定)您的本地环境Windows
和实时服务器是Linux
. 因此,如果在本地服务器上company
使用类类文件,company.php
那么它Company.php
在本地服务器上是相同的,但Linux
遵循区分大小写的规则,因此它将company.php
和读取Company.php
为两个不同的文件。
So, if you have file name used Company.php
then make sure you are refering the class using same case as Company
not company
(lower), in windows c
and C
doesn't matter but on Linux/Unix
it does because of it's case sensitive nature.
因此,如果您使用了文件名,那么请Company.php
确保您在 Windows 中使用与Company
not company
(较低)相同的大小写来引用类c
,C
这无关紧要,但Linux/Unix
由于它区分大小写的性质,所以在它上面确实如此。
回答by Amr
I have faced the same problem when I added/created a new model class called Follower_Group
in a project I worked on, and after some search I came to a solutionthat worked pretty well in my case. Try this:
当我Follower_Group
在我从事的项目中添加/创建一个新的模型类时,我遇到了同样的问题,经过一番搜索,我找到了一个在我的案例中效果很好的解决方案。尝试这个:
- Execute the command
composer dump-autoload
in your local machine's terminal. - Re-upload these 2 folders
/bootstrap
and/vendor/composer
from your local machine to your server.
composer dump-autoload
在本地机器的终端中执行命令。- 重新上传这 2 个文件夹
/bootstrap
并/vendor/composer
从您的本地机器上传到您的服务器。
回答by Mohamed Kawsara
In case you are using git, and you want Git to be case sensitive, adjust its configs:
如果您正在使用 git,并且希望 Git 区分大小写,请调整其配置:
Just use the following command for the current repository:
只需对当前存储库使用以下命令:
git config core.ignorecase false
git config core.ignorecase false
For global setting:
对于全局设置:
git config --global core.ignorecase false
git config --global core.ignorecase false
回答by Jnanaranjan
During the upload sometimes it happens like the files get uploaded but the content inside it is blank.
在上传过程中,有时会发生文件被上传但里面的内容是空白的情况。
I faced similar issue and fixed it re-uploading the file.
我遇到了类似的问题并修复了它重新上传文件。
When I see the file on the server, it is of 0 bytes so i have to re upload the local file to fix the issue.
当我在服务器上看到文件时,它是 0 字节,所以我必须重新上传本地文件来解决这个问题。
回答by dev.mohamed
Run command composer dump-autoload
in your local machine terminal, and then Re-upload composer folder from vendor in local machine to your server.
composer dump-autoload
在您的本地机器终端中运行命令,然后将本地机器中的供应商的 composer 文件夹重新上传到您的服务器。
回答by Roga Men
THIS WORKS FOR ME ->
on your live server execute: composer install
This should install all the necessary packages that are missing.
这对我有用 -> 在您的实时服务器上执行:composer install
这应该安装所有缺少的必要软件包。
Hope this help someone!
希望这对某人有所帮助!