Laravel stores to many copies of images at first time upload in storage folder

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

here is image how it stores in storage folder

anyone guide me why it is doing this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3cILp60
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time