Custom full-page Livewire component response headers

Custom full-page Livewire component response headers

When using full-page components, you can hook into the response object to, for example, set custom response headers.

When using Laravel you can use the response() helper to return your blade view and attach custom headers.

1return response()->view('hello', $data, 200)->header('Content-Type', $type);

In Livewire this wasn't possible due to how full-page components worked. So I've made a PR to add this functionallity. All you have to do is call response() on your view() helper and use a closure to access the Response object and make any adjustments. In the following example we add a custom x-livewire-forever header to the response.

1class Dashboard extends Component
2{
3 public function render()
4 {
5 return view('livewire.dashboard')->response(function(Response $response) {
6 $response->header('x-livewire-forever', true);
7 });
8 }
9}
To navigate
Press Enter to select