In your migration the images field should be nullable:
$table->string('images')->nullable();
Hi, I have this error from yesterday i tried many times to solve it but i can't so i need someone to guide me :
Product model
class Product extends Model
{
protected $fillable =[
'category_id','images','name_ar','name_en','shortDetails_ar','shortDetails_en',
'quantity','size','color','ref','description_ar','description_en','additionalInfo_ar','additionalInfo_en',
'price','created_at','updated_at',
];
Migration
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('category_id');
$table->string('images');
$table->string('name_ar');
$table->string('name_en');
$table->text('shortDetails_ar');
$table->text('shortDetails_en');
$table->integer('quantity');
$table->string('size');
$table->string('color');
$table->string('ref');
$table->text('description_ar');
$table->text('description_en');
$table->text('additionalInfo_ar');
$table->text('additionalInfo_en');
$table->double('price', 15, 8);
$table->timestamps();
});
Controller code
$product = Product::create([
'category_id'=> $request->category,
'name_ar'=> $request->name_ar,
'name_en'=> $request->name_en,
'shortDetails_ar'=> $request->shortDetails_ar,
'shortDetails_en'=> $request->shortDetails_en,
'quantity'=> $request->quantity,
'size'=> $request->size,
'color'=> $request->color,
'ref'=> $request->ref,
'description_ar'=> $request->description_ar,
'description_en'=> $request->description_en,
'additionalInfo_ar'=> $request->additionalInfo_ar,
'additionalInfo_en'=> $request->additionalInfo_en,
'price'=> $request->price,
]);
$product->save();
if($request->hasfile('images'))
{
foreach ($request->file('images') as $key => $value)
{
if ($products = $value)
{
$destinationPath = 'public/files/'; // upload path
$fileName = date('YmdHis') . "." . $products->getClientOriginalExtension();
$products->move($destinationPath, $fileName);
$save[]['images'] = "$fileName";
}
}
}
Product::insert($save); // store file into mysql database
Please or to participate in this conversation.