I am creating a web-based app for Internship, and created a CRUD for companies info including company logo image, every thing works perfectly, until I try to edit the image for the company, it does not update the image_path on the DB if I tried to update the image it shows the alt for that img tag.
Here is the Controller Code for the Update Function:
public function update(Request $request, $id)
{
$validated = $request->validate([
'name' => 'required|max:255',
'eco_sector' => 'required',
'sector' => 'required',
'email' => 'required',
'phone_number' => 'required',
'image' => 'mimes:jpg,png,jpeg|max:5048',
]);
if ($companyImage = $request->file('image')) {
$oldImageName = $request->old_image;
$ImageName = time() . '-' . $request->name . '.' . $request->image->getClientOriginalExtension();
$up_location = 'images/company/';
$newImage = $up_location . $ImageName;
$companyImage->move($up_location, $ImageName);
unlink($oldImageName);
company::find($id)->update([
'name' => $request->name,
'eco_sector' => $request->eco_sector,
'sector' => $request->sector,
'email' => $request->email,
'phone_number' => $request->phone_number,
'image_path' => $newImage,
'updated_at' => Carbon::now(),
]);
return Redirect()->route('company.index')->with('success', 'Company Record Updated Successfully');
} else {
company::find($id)->update([
'name' => $request->name,
'eco_sector' => $request->eco_sector,
'sector' => $request->sector,
'email' => $request->email,
'phone_number' => $request->phone_number,
'updated_at' => Carbon::now(),
]);
return Redirect()->route('company.index')->with('success', 'Company Record Updated Successfully');
}
}
Blade View
<div class="d-flex flex-row mb-3"><img src="{{asset($data->image_path)}}" width="70" alt="Company Image">
<div class="d-flex flex-column ml-2"><span>{{ $data->name }}</span><span class="text-black-50">{{ $data->eco_sector }}</span><span class="ratings"><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i></span></div>
</div>
What am I doing Wrong ?