Hey I have problem when I insert my data from laravel to MySQL with error SQLSTATE[23000]: Integrity constraint violation: 4025 CONSTRAINT
Here is store controller
public function store(Request $request)
{
// $faker = Faker::create('id_ID');
$image = $request->file('Product_photo');
$extension = $image->getClientOriginalExtension();
$name = $request->Name;
$file_name = $name.'.'.$extension;
$image->move("images/listcar/", $file_name);
DB::table('car')
->insert([
//'id' => $faker->unique()->numberBetween($min = 0, $max = 200),
'product_photo' => $file_name,
'name' => $request->Name,
'production_year' => $request->Production_year,
'price' => $request->Price,
'merk' => $request->Merk,
'description' => $request->Description,
'varian' => $request->Variant,
'machine' =>$request->Machine,
'transmision' => $request->Transmision,
'wheel' => $request->Wheel,
]);
return redirect('/admin');
Here is my blade
<body>
<h1>Tambah Mobil</h1>
<div class="container">
<form action="/car/add" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<th>Nama</th><br>
<input type="text" name="Name" value=""><br/><br>
<th>Tahun Produksi</th><br>
<input type="text" name="Production_year" value=""><br/><br>
<th>Harga</th><br>
<input type="number" name="Price" value=""><br/><br>
<th>Select Product Image</th><br>
<input type="file" name="Product_photo" /><br/><br>
<th>Merek</th><br>
<input type="text" name="Merk" value=""><br/><br>
<th>Deskripsi</th><br>
<input type="textarea" name="Description" value=""><br/><br>
<th>Varian</th><br>
<input type="text" name="Variant" value=""><br/><br>
<th>Mesin</th><br>
<input type="text" name="Machine" value=""><br/><br>
<th>Transmisi</th><br>
<input type="text" name="Transmision" value=""><br/><br>
<th>Penggerak Roda</th><br>
<input type="text" name="Wheel" value=""><br/><br>
<br>
<input class="btn btn-primary" type="submit" value="Tambah Data Mobil">
</form>
<br>
<br>
</div>
I really dont know where I went wrong, so please tell me if there is a wrong concepts
'id' => $faker->unique()->numberBetween($min = 0, $max = 200),
id
asauto increment
and then no need of setting it throughFaker
.