Laravel Responses: Creating Responses
Strings & Arrays
Response Objects
Route::get('home', function () {
return response('Hello World', 200)
->header('Content-Type', 'text/plain');
}); Returning a full Response instance allows you to customize the response's HTTP status code and headers.
Attaching Headers To Responses
Return response($content)
->header('Content-Type', $type)
->header('X-Header-One', 'Header Value')
->header('X-Header-Two', 'Header Value'); Return response($content)
->withHeaders([
'Content-Type' => $type,
'X-Header-One' => 'Header Value',
'X-Header-Two' => 'Header Value',
]); You may use the header method to add a series of headers to the response before sending it back to the user.
You may use the withHeaders method to specify an array of headers to be added to the response.
Semantic portal