I have tried many ways to update image but its not working at all though I can update other data except image.
code for saving Image and other inputs
public function store(Request $request)
{
$fileName = null;
if($request->file('image')){
$fileName = strtotime(Carbon::now());
$fileName = $fileName.".".$request->file('image')->extension();
$uploadPath = (public_path($this->uploadPath."/".$fileName));
move_uploaded_file($request->file('image'), $uploadPath);
}
$data = $request->all();
$data['image'] = $fileName;
if(Covidrecord::create($data))
{
return redirect()->route('store')->with(['msg'=>"User create successfully"]);
return redirect()->route('store')->withError(['msg'=>"User cannot be registerd at the moment"]);
}
}
Code for UPDATING
public function update(Request $request,Covidrecord $covidrecord, $id)
{
$data = Covidrecord::find($id);
$fileName = null;
if($request->file('image')){
$fileName = strtotime(Carbon::now());
$fileName = $fileName.".".$request->file('image')->extension();
$uploadPath = (public_path($this->uploadPath."/".$fileName));
move_uploaded_file($request->file('image'), $uploadPath);
}
$data = $request->all();
$data['image'] = $fileName;
$covidrecord->update($request->all());
return redirect()->route('allrecord')->with(['msg'=>"User create successfully"]);
}
Blade
<div class="input-group">
<input class="form-control" type="file" placeholder="Upload Image" name="image" >
<img src=""
</div>
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire