I want to save a pdf file in the storage folder but when I insert a file in my form and I click on the button, it displays me the error "Path cannot be empty". However, the path is not empty. Here is my function that allows me to do this :
public function getFilenametostore(Request $request): string
{
$filenamewithextension = $request->file('profile_pdf')->getClientOriginalName();
$filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);
//get file extension
$extension = $request->file('profile_pdf')->getClientOriginalExtension();
$time = time();
//filename to store
$filenametostore = $filename . '_' . $time . '.' . $extension;
//The problem is here
$request->file('profile_pdf')->storeAs('profile_pdfs', $filenametostore);
return $filenametostore;
}
in storage, there is: storage/app/public/profile_pdfs/
My Form :
<form action="{{url('poste')}}" method="post" enctype="multipart/form-data">
@csrf
<div class="mt-2">
<label class=" block text-sm text-gray-600" for="cus_email">Upload</label>
<input class="px-2 py-2 text-gray-700 rounded" type="file" name="profile_pdf" id="exampleInputFile">
</div>
<div class="mt-4">
<button class="px-4 py-1 text-white font-light tracking-wider bg-gray-900 rounded" type="submit">Publier</button>
</div>
</form>
My controller :
if($files = $request->hasFile('profile_pdf'))
{
$filenametostore = $this->getFilenametostore($request);
$p = new Poste;
$p->pdf = $filenametostore;
$p->save();
return redirect()->route('poste.index');
}

