Laravel 5 - 更改模型文件位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29451501/
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 5 - Change model file location
提问by Anindit Karmakar
I moved over to Laravel 5 from Laravel 4. One major change I'm seeing is that all model files must be placed under the /app
directory.
我从 Laravel 4 转移到 Laravel 5。我看到的一个主要变化是所有模型文件都必须放在该/app
目录下。
How do I configure my laravel 5 installation so that I can place my model files under /app/Models
and also use the models in the usual FooModel::with(...)
(for example) way?
我如何配置我的 Laravel 5 安装,以便我可以将我的模型文件放在下面/app/Models
并以通常的FooModel::with(...)
(例如)方式使用模型?
采纳答案by ceejayoz
Add the folder to the composer.json
classmap:
将文件夹添加到类composer.json
映射:
"autoload": {
"classmap": [
"database",
"app/Models"
]
}
回答by Conrad Warhol
you just need to namespace the models accordingly.
您只需要相应地命名模型。
namespace App\Models\User
and wherever you may need to use them just reference them with the correct namespace.
无论您在哪里可能需要使用它们,只需使用正确的命名空间引用它们即可。
use App\Models\User
回答by Nooovice Boooy
Only Twoplaces to change ...
只有两个地方可以改变......
1) At namespacein User.php
1) 在User.php 中的命名空间
namespace App\Models;
When Use it,
使用时,
use App\Models\User;
2) In config/auth.php
2) 在 config/auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
Note: After changing 2) ... Don't forget to php artisan config:cache
and php artisan config:clear
at command line.
注:更改2)后...不要忘了php artisan config:cache
,并php artisan config:clear
在命令行。