/ Laravel / 상세보기

response() Laravel 전역 헬퍼 함수

👁 조회 4 📅 2026-04-05


// Illuminate\Http\Response 클래스를 반환

// vendor/laravel/framework/src/Illuminate/Http/Response.php



[예제]


response()->download($path, $file->bf_source);


// 내부적으로 아래 HTTP 헤더를 자동 설정해줘요

Content-Type: application/octet-stream

Content-Disposition: attachment; filename="파일명.png"

Content-Length: 파일크기



※ 순수 PHP 와 비교


// 순수 PHP 방식 (직접 헤더 설정)

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename="' . $filename . '"');

header('Content-Length: ' . filesize($path));

readfile($path);

exit;


// Laravel 방식 (한 줄로 처리)

return response()->download($path, $file->bf_source);



◎ 자주 쓰는 response() 종류

response()->download() // 파일 다운로드

response()->json() // JSON 반환 (API)

response()->view() // View 반환

response()->redirect() // 리다이렉트