I am using mysql v5.7 and laravel 5.5. When I try to "add product" the following error occurs.
SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value
My products table
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->string('size');
$table->string('price');
$table->string('image');
$table->timestamps();
});
}
My ProductController with store method
public function store(Request $request)
{
//validation
$this->validate($request,[
'name'=> 'required',
'description'=>'required',
'size'=>'required',
'price'=>'required',
'image'=>'image|mimes:png,jpg,jpeg|max:10000'
]);
//image upload
$image=$request->image;
if($image){
$imageName=$image->getClientOriginalName();
$image->move('images',$imageName);
$formInput['image']=$imageName;
}
Product::create($formInput);
return redirect()->route('product.index');
}
When I add ->nullable
method to the field, there is no error but the data in table is null.
Please help me...
$formInput
ever defined? As far as I can see it only has one key, which is image. – Classified