While updating the record, I have created an option to replace the image using file upload, but when doing so in $request->file('headerbanner'), it is getting saved in DB as /tmp/phpCccApH
Controller Code :
public function update(Request $request, $id)
{
$clientnewstore = Clientusers::find($id);
if($request->hasFile('headerbanner')) {
$headerbanner = $request->file('headerbanner');
$mod_headerbanner= date('Y-m-d').'-'.'MQ'.rand(1, 999).'-'.$headerbanner->getClientOriginalName();
$headerbanner->storeAs(public_path().'banners',$mod_headerbanner);
$request['headerbanner'] = $mod_headerbanner;
}
if($request->hasFile('footerbanner')) {
$footerbanner = $request->file('footerbanner');
$mod_footerbanner= date('Y-m-d').'-'.'MQ'.rand(1, 999).'-'.$footerbanner->getClientOriginalName();
$footerbanner->storeAs('banners',$mod_footerbanner);
$request['footerbanner'] = $mod_footerbanner;
}
Clientusers::find($id)->update($request->all());
$request->session()->flash('message','Record Successfully Updated');
return redirect('/user_accounts');
}
HTML file
<form action="/user_accounts" method="POST" enctype="multipart/form-data">
<h4> Header / Footer Settings</h4>
<div class="form-group row py-2">
<div class="col-sm-6 pr-4">
<label for="headerbanner">Header Banner</label>
<input type="file" class="form-control" id="headerbanner" name="headerbanner" />
</div>
<div class="col-sm-6">
<label for="footerbanner">Footer Banner</label>
<input type="file" class="form-control" id="footerbanner" class="form-control" name="footerbanner" >
</div>
</div>
<div class="float-right text-right">
<button type="submit" class="btn btn-success float-right">
<i class="fas fa-check px-2"></i> Save
</button>
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire