I’m trying to nake a simple to save a simple Product in my db but for a reason I don’t understand, I get this error each time I try to save.
SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘files’ in ‘field list’
The thing is that I don’t have any Files column and I don’t want to have one.
Here’s my migration file :
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();
});
}
Here’s my comtroller file :
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');
}
I’m confused!
Edit :
Here’s the dd of $request
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
]
It says "files" => null, but I don’t know where that Files field comes from.
Nothing in my migrations and nothing in the db (PhpMyAdmin).
Really strange!
2
Answers
There is a files in your request, so you get this error. You can save your query in this way, to prevent extra field :
Use
$request->validated()
instead of$request->all()