I need to uploaded a pdf file and show it, but when I tried to show it I get a 404 not found. This is my controller store and show functions. It uploads successfully but doesn't show the pdf.
public function store(Request $request)
{
$request->validate([
'file' => 'required|mimes:pdf|max:2048',
]);
$fileModel = new pdf();
$pdf = $request->file;
$fileName = time().'.'.$pdf->getClientOriginalExtension();
$filePath = $pdf->storeAs('public/uploads', $fileName);
$fileModel->name = $fileName;
$fileModel->file = '/storage/' . $filePath;
// storage_path($filePath);'
$fileModel->save();
return redirect()->route('pdfs.index')
->with('success','File has been uploaded.')
->with('pdf', $fileName);
}
/**
* Display the specified resource.
*
* @param \App\Models\Pdf $pdf
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$fileModel = Pdf::find($id);
return view('pdfs.show', compact('fileModel'));
}