inertia
inertia copied to clipboard
image upload can not be uploaded into database. all other form is okay.
Discussed in https://github.com/inertiajs/inertia/discussions/1822
Originally posted by mangga88d March 9, 2024
</div>
</div>
<div class="grid md:gap-6">
<div class="relative z-0 w-full mb-6 group">
<el-upload
v-model:file-list="productImages"
list-type="picture-card"
multiple
type="file"
ref="file"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:on-change="handleFileChange"
>
<el-icon>
<Plus />
</el-icon>
</el-upload>
</div>
</div>
public function store(Request $request)
{
$request->validate([
'title' => 'required',
'price' => 'required',
'quantity' => 'required',
'description' => 'required',
'product_images' => 'required|image|mimes:jpeg,jpg,png,bmp,gif,svg|max:2048',
]);
$products = Product::create([
'title' => $request['title'],
'price' => $request['price'],
'quantity' => $request['quantity'],
'description' => $request['description'],
'category_id' => $request['category_id'],
'brand_id' => $request['brand_id'],
]);
if ($request->hasFile('product_images')) {
$productImage = $request->file('product_images');
foreach ($productImage as $productImages) {
$imageName = time() . '.' . $productImages->getClientOriginalExtension();
$productImages->store(('public'), $imageName);
ProductImage::create([
'product_id' => $products['id'],
'product_images' => $imageName,
]);
}
return Redirect::route('admin.product.index', [])->with('success', 'Product created successfully.');
}
}</div>
Please format your code for readability, explain what Inertia-specific issue you're running into, and consider only opening an issue in one place so others can help you more effectively.
Let's keep this a discussion (#1822) until it's been verified that this is an Inertia bug, thanks 👍