我對 Laravel 專案從 v5.7 到 v9 執行了早就應該更新的更新,但遇到了Target class does not exist錯誤。我找到了這個指南并使用了第一種方法來解決錯誤(將命名空間添加到 RoutesServiceProvider.php 啟動函式中)。這解決了該錯誤,但現在,一切都在給我Class "App\Whatever" not found。
我確實注意到模型現在存盤在Models目錄中的一個目錄中,app而不是直接存盤在. 我認為這可能會在我的控制器頂部打破我的線路,所以我也嘗試過(因為“a”在目錄名稱中是小寫的)但沒有效果。appModelsuse App\Whatever;use App\Models\Whateveruse 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);
...
uj5u.com熱心網友回復:
Laravel 7/8/9 堅持嚴格的命名空間。當您將模型移動到新目錄時,您需要更新模型本身(如果已指定)和任何具有use模型的檔案中的命名空間。如果模型從 移動app/到app/models,則必須將命名空間更改為App/Models
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/439806.html
