Level 6
Did you ever find a solution? I'm facing the same issue with Laravel 12
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to view pdf file stored in S3 in a new tab .. but my code downloaded it
route
Route::resource('legislations', LegislationController::class);
store
public function store(Request $request)
{
$validated = $request->validate([
'file' => 'required',
]);
$name = $request->leg_number . '_' . $request->leg_year . '.pdf';
Storage::disk('s3')->put($name, file_get_contents($request->file), 'public');
$validated['leg_path'] = $name;
Legislation::create($validated);
}
show
public function show(Legislation $legislation)
{
$content = Storage::disk('s3')->get('documents/' . $legislation->leg_path);
$header = [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="' . $legislation->leg_path . '"'
];
return Response::make($content, 200, $header);
}
view
<a href="{{ route('admin.legislations.show', $leg->id) }}" target="_blank"></a>
Please or to participate in this conversation.