我试图在我的数据库中简单地保存一个简单的产品,但由于我不明白的原因,每次尝试保存时都会收到此错误。SQLSTATE[42S22]:未找到列:1054“字段列表”中的未知列“文件”问题是我没有任何“文件”列,而且我不想有一个。这是我的迁移文件: public function up(){ Schema::create('formations', function (Blueprint $table) { $table->id(); $table->string('name')->unique(); $table->string('subtitle'); $table->text('description'); $table->integer('price'); $table->integer('category_id'); $table->integer('level_id'); $table->timestamps(); });}这是我的控制器文件:public function store(Request $request){ $request->validate(([ 'name' => 'required|string', 'price' => 'required', 'description' => 'required', 'subtitle' => 'required', 'category_id' => 'required', 'level_id' => 'required', ])); Formation::create($request->all()); return redirect()->route('admin.formations.index')->with('success','Formation ajoutée');}我很困惑!编辑 :这是 $request 的 dd array:8 [▼ "_token" => "AGHU3QcTxNEd29ZVJ2mNM1lGMwAHDMqbIQEG4XxU" "name" => "Lh lU" "price" => "125" "category_id" => "1" "level_id" => "2" "subtitle" => "Inke hune us kogru wuwuvat kerudowe anuzti gosvili dutoc wiv dufeaba job. Vaamcoj zodli kecuh wu ri hari sisalal gajesma ate ihloef egkes li zu. Ezfaaw uzared c ▶" "description" => "<p>gg<br></p>" "files" => null]它说“files”=> null,但我不知道该“文件”字段来自哪里。我的迁移中没有任何内容,数据库(PhpMyAdmin)中也没有任何内容。真是奇怪啊!
2 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
您的请求中有一个文件,因此您会收到此错误。您可以通过这种方式保存查询,以防止出现额外的字段:
$q = new Formation();
$q->name = $request->name;
$q->price = $request->price;
$q->description = $request->description;
$q->subtitle = $request->subtitle;
$q->category_id = $request->category_id;
$q->level_id = $request->level_id;
$q->save();
qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
使用$request->validated()而不是$request->all()
public function store(Request $request)
{
// ...
Formation::create($request->validated());
// ...
}
- 2 回答
- 0 关注
- 120 浏览
添加回答
举报
0/150
提交
取消