Submitting Inertia Forms to a New Window in Laravel/Vue Applications
In Laravel applications using Inertia.js and Vue.js, there might be scenarios where you need to submit a form to a new window.…
When you return an Inertia response using Inertia::render(), it doesn't return a standard Laravel response object directly. Instead, it returns an instance of Inertia\Response, which is then converted to a standard Laravel response when it's actually sent back to the client.
To modify headers in an Inertia response, you need to:
Inertia::render().toResponse() method. This method takes the current request as an argument and converts the Inertia response to a Laravel response.headers->set() method.Here's an example of a Laravel controller method that modifies headers in an Inertia response:
use Inertia\Inertia;
class ExampleController extends Controller
{
public function show()
{
// Step 1: Create an Inertia response
$inertiaResponse = Inertia::render('ExampleComponent', [
'data' => 'some data'
]);
// Step 2: Convert the Inertia response to a Laravel response
$response = $inertiaResponse->toResponse(request());
// Step 3: Modify the headers
$response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Expires', '0');
// Step 4: Return the response
return $response;
}
}
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com