I want to update user image but it's not getting updated. I have used following controller for updating the image.. Can you suggest what's the mistake in controller function?
View part :
<div class="form-group">
<label>Image Upload</label>
<input type="file" name="image" id="image"><img src="" width="200px"/></br>
</div>
Controller function :
public function update(Request $request, $id)
{
$data=Course::findOrFail($id);
if ($request->hasFile('image'))
{
$file = $request->file('image');
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$name = $timestamp. '-' .$file->getClientOriginalName();
$data->image = $name;
$file->move(public_path().'/images/', $name);
}
$data->update($request->all());
return redirect('course');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire