Laravel 未找到模型
Laravel Model not being found
您好,我在 class 中使用模型时遇到问题,显示的错误是 Error
Class 'App\Models\RegisteredUsers' 未找到。
我已确保名称空间与正在使用的名称相匹配,但我反复遇到相同的错误。
型号代码
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RegisteredUsers extends Model
{
//
}
控制器代码
<?php
namespace App\Http\Controllers;
use App\Models\RegisteredUsers;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
class RegisterUser extends Controller
{
$UserObj = new RegisteredUsers();
}
目录
App/Http/Controllers/RegisterUser - 控制器
App/Http/Models/RegisteredUser - 型号
我使用命令行和 PHP artisan 创建了模型和控制器。
我已经尝试了解决方案
laravel model class not found
以及
和一些 laracast 问题,但我仍然得到错误。
可能需要重建类图
composer dump-autoload
您的错误是 App/Http/Models/RegisteredUser 并且 使用 App\Models\RegisteredUsers;,您是否将模型置于 Http 中? .这是不正确的,模型应该在 App 根目录中,所以你在错误的地方调用 RegisteredUser
在您的 RegsiteredUser
模型中使用 App\Models
命名空间,RegisteredUser.php 模型文件必须位于 app/Models/RegisteredUser.php目录。尝试将 Models 文件夹移出 Http 文件夹。从现在开始,您再也不能将 Models 文件夹放在 Http 文件夹中了。
您好,我在 class 中使用模型时遇到问题,显示的错误是 Error Class 'App\Models\RegisteredUsers' 未找到。
我已确保名称空间与正在使用的名称相匹配,但我反复遇到相同的错误。
型号代码
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RegisteredUsers extends Model
{
//
}
控制器代码
<?php
namespace App\Http\Controllers;
use App\Models\RegisteredUsers;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
class RegisterUser extends Controller
{
$UserObj = new RegisteredUsers();
}
目录 App/Http/Controllers/RegisterUser - 控制器
App/Http/Models/RegisteredUser - 型号
我使用命令行和 PHP artisan 创建了模型和控制器。
我已经尝试了解决方案
laravel model class not found
以及
可能需要重建类图
composer dump-autoload
您的错误是 App/Http/Models/RegisteredUser 并且 使用 App\Models\RegisteredUsers;,您是否将模型置于 Http 中? .这是不正确的,模型应该在 App 根目录中,所以你在错误的地方调用 RegisteredUser
在您的 RegsiteredUser
模型中使用 App\Models
命名空间,RegisteredUser.php 模型文件必须位于 app/Models/RegisteredUser.php目录。尝试将 Models 文件夹移出 Http 文件夹。从现在开始,您再也不能将 Models 文件夹放在 Http 文件夹中了。