ImageController::store($request->file('image'), 'collection');
ImageController???
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am updating an item in InertiaJS, but when adding an image, the image file isn't being sent to the controller.
<div className="col col-span-2">
<InputLabel>Image</InputLabel>
<input id="image" name="image" onChange={e => setData('image', e.target.files[0])} className="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400" aria-describedby="file_input_help" type="file" required />
<p className="mt-1 text-sm text-gray-500 dark:text-gray-300" id="file_input_help">SVG, PNG, JPG or GIF (Ensure file size is low for fast loading times).</p>
{processing && (
<div value={processing.percentage} max="100">
{processing.percentage}%
</div>
)}
</div>
const { data, setData, put, processing, errors, reset } = useForm({
id: '',
collection_id: '',
category_id: '',
name: '',
description: '',
image: '',
price: '',
amount: '',
});
const submit = (e) => {
e.preventDefault();
put('/admin/product/{product}', data);
setShowUpdate(false);
let index = tuples.findIndex(obj => obj.id === tuple.id);
if (index !== -1) {
let updateTuples = [
...tuples.slice(0, index),
data,
...tuples.slice(index + 1)
];
setTuples(updateTuples);
}
};
public function update(Request $request)
{
dd($request);
$path = ImageController::store($request->file('image'), 'collection');
$data = Product::find($request->id);
$data->collection_id = $request->collection_id;
$data->category_id = $request->category_id;
$data->name = $request->name;
$data->description = $request->description;
$data->image = $request->image;
$data->price = $request->price;
$data->amount = $request->amount;
$data->image = $path;
$data->save();
}
PUT|PATCH admin/product/{product} ......................................... product.update › ProductController@update
@Randy_Johnson sorry for misread on my part - I didn't account for Inertia.
You need to use a post rather than put because multipart form data is not supported for the latter. Instead, spoof the method using a _method data property
Please or to participate in this conversation.