//first run this command to generate symbolic link
php artisan storage:link
//then in controller function
$fileTemp = $request->file('file');
if($fileTemp->isValid()){
$fileExtension = $fileTemp->getClientOriginalExtension();
$fileName = Str::random(4). '.'. $fileExtension;
$path = $fileTemp->storeAs(
'public/documents', $fileName
);
}
//above code will save your file in 'storage/app/public/documents' location
//and using symbolic link we can access this file here 'public/storage/documents'
//Now Open or download file in blade template
<a href="{{url(Storage::url($document['file']))}}">Open/Download</a>
class FileController extends Controller
{
// ...
public function upload(Request $request)
{
$uniqueFileName = uniqid() . $request->get('upload_file')->getClientOriginalName() . '.' . $request->get('upload_file')->getClientOriginalExtension());
$request->get('upload_file')->move(public_path('files') . $uniqueFileName);
return redirect()->back()->with('success', 'File uploaded successfully.');
}
// ...
}