I am confused about this error guys. I have no idea what is wrong here.
edit.blade:
<input type="file" name="image" class="form-control" placeholder="image">
Controller:
public function update(Request $request, $id)
{
$sales = sales::find($id);
$request->validate([
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($request->hasFile('image')) {
$destination_path = 'public/imagen/shop_logo';
$image = $request->file('image');
$image_name = $image->getClientOriginalName();
$path = $request->file('image')->storeAs($destination_path, $image_name);
$input['image']=$image_name;
}
$sales->image = $request->input('image');
$sales->save();
From the source code above I do not see any error there. If you guys know I need some help here
3
Answers
The error is what it says i.e. the image column on your sales table isn’t nullable.
Then if you’re inputting image in the form and you’re still getting this error then make sure you’ve included
enctype='multipart/form-data'
in the form.Also how can you store image directly in the db? You’re supposed to store the image path in the db. Look at the following code for reference.
Here I’ve used Intervention Image library.
Best Practice to store images in the table
Validate your image
Upload a file to a specific location
Assign the saved path of the image to the
image
attribute of the sales object.Documentation