laravel - 即使我已导入,也找不到类“App\Models\Registration”
问题描述
找不到类“App\Models\Registration”,我有导入注册类
我正在尝试使用相应的主题数组保存 student_id 当我转储 dd($request->all()) 时,我得到了例外结果
"student_id" => "1"
"subjects" => array:2 [▼
0 => "1"
1 => "2"
]
但是当我尝试保存到数据库时出现异常
这是我的注册计划
Schema::create('registrations', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('student_id')->index();
$table->string('subjects');
$table->foreign('student_id')->references('id')->on('students');
$table->timestamps();;
});
这是我的注册模型
class Registration extends Model
{
protected $table = 'registrations';
protected $fillable = ['student_id','subjects'];
protected $cast = [
'student_id' => 'Integer',
'subjects' => 'array',
];
public function student(){
$this->belongsTo(Student::class);
}
public function subjects()
{
$this->hasMany(Subject::class);
}
}
我正在使用复选框数组来获取主题
<input class="form-check-input" name="subjects[]" value="{{$subject->id}}" type="checkbox">
这是注册控制器代码,我已经导入了注册模型
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Models\Registration;
use App\Http\Controllers\BaseController;
class RegistrationController extends BaseController
{
public function store(Request $request)
{
$registration = Registration::create(request()->validate([
'student_id' => 'required|integer',
'subjects' => 'required',
'subjects.*'=> 'accepted',
]));
}
我想用主题数组保存 student_id
学生科目
1 [2,4,5]enter code here
解决方案
我认为您需要添加一个命名空间。
<?php
namespace App\Models;
class Registration extends Model { ... }
?>
此外,您的模型必须存储在App/Models/ Registration.php目录中。
推荐阅读
- discord - 您将如何使用 discord.js v.12 循环命令?
- specflow - 如何让 NUnit Assert.Pass() 测试报告为通过 SpecFlow+ Runner
- google-drive-api - 共享驱动器在 webui 中消失
- python - 一年中各月份按站点名称排列的 Pandas 箱线图
- php - PHP + MYSQL 选择行并显示
- r - 用于多类分类的 GBM OOF 预测(通过 CV)
- android - 如何访问 SqlNormalizedCacheFactory 数据库进行调试?
- mysql - 分层数据使用数据库 MySql 版本 8.0.17
- html - 为什么分辨率会因我所在的页面而异(html/css)仅限 Chrome
- azure - Azure 发布配置文件 - 如何将 SkipExtraFilesOnServer 添加到现有应用程序