提问人:Sam 提问时间:3/8/2022 最后编辑:Sam 更新时间:3/8/2022 访问量:611
Laravel升级破坏了模型路径
Laravel upgrade broke model paths
问:
我已经对 Laravel 项目从 v5.7 到 v9 进行了早就应该更新,但遇到了错误。我找到了本指南并使用第一种方法来解决错误(将命名空间添加到 RoutesServiceProvider.php 启动函数中)。这解决了那个错误,但现在,一切都给了我.Target class does not exist
Class "App\Whatever" not found
我确实注意到模型现在存储在该目录中的目录中,而不是直接存储在 中,因此已将它们移至 。我想这可能会破坏我在控制器顶部的行,所以我也尝试过(因为“a”在目录名称中是小写的),但没有效果。Models
app
app
Models
use App\Whatever;
use App\Models\Whatever
use app\Models\Whatever
我应该注意,我并没有很好地掌握命名空间、MVC 框架等,所以 ELI5 等:-)
我的一些控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Thing;
use App\AnotherThing;
...
public function thing_summary($id) // show the summary view of the thing
{
if(Auth::check()) {
$thing = Thing::find($id);
...
答:
1赞
aynber
3/8/2022
#1
Laravel 7/8/9 坚持严格的命名间距。将模型移动到新目录时,需要更新模型本身(如果已指定)中的命名空间以及具有模型的任何文件。如果模型从 移动到 ,则命名空间必须更改为use
app/
app/models
App/Models
评论