Laravel 升级破坏了模型路径

Laravel upgrade broke model paths

我对从 v5.7 到 v9 的 Laravel 项目进行了一次逾期已久的更新,并且 运行 出现了 Target class does not exist 错误。我找到了this guide并使用第一种方法解决了错误(将命名空间添加到RoutesServiceProvider.php引导函数中)。这解决了那个错误,但现在,一切都给了我 Class "App\Whatever" not found.

我确实注意到模型现在存储在 app 目录中的 Models 目录中,而不是直接存储在 app 中,因此已将它们移动到 Models。我想这可能会破坏我控制器顶部的 use App\Whatever; 行,所以我尝试了 use App\Models\Whateveruse app\Models\Whatever (因为目录名称中的“a”是小写)但没有效果。

我应该注意到我并没有真正掌握名称空间、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);
...

Laravel 7/8/9 坚持严格的命名空间。当您将模型移动到新目录时,您需要更新模型本身的命名空间(如果指定的话)以及任何具有模型 use 的文件。如果模型从 app/ 移动到 app/models,则命名空间必须更改为 App/Models