when I upload one image in Laravel it stores correctly in the database but it stores 4 times one image in the storage folder here is my function which store data from form
public function store(Request $request)
{
//
$request->validate([
'name'=>'required',
'intro'=>'required',
'description'=>'required',
'profile'=>'image|nullable|max:1999'
]);
$fileNameToStore='';
if($request->hasFile('profile')){
$fileNameWithExt =$request->file('profile')->getClientOriginalName();
$fileName = pathinfo($fileNameWithExt, PATHINFO_FILENAME );
$extension = $request->file('profile')->getClientOriginalExtension();
$fileNameToStore= $fileName.'_'.time().'.'.$extension;
$path = $request->file('profile')->storeAs('public',$fileNameToStore);
}
$data=$request->except('token');
$data['profile']=$fileNameToStore;
about::create($data);
return redirect()->route('admin.aboute.create')->with('msg', 'Your profile
has been added successfully');
}
I added my profile details only one time, it stores all data in database very well but, it stores my profile image in storage folder 4 times
anyone guide me why it is doing this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire