Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
Laravel testing forms using Inertia

I am trying to find the best method for testing forms in Laravel. I'm using Inertia and Laravel Fortify for user accounts.

If I run what I'm trying to test in the web browser it works as expected, however, when I run the test I'm getting a 419 status response with the error being: CSRF token mismatch.

According to documentation for Inertia in Laravel it handles CSRF protection for us (which I guess is why running this manually in the browser works): https://inertiajs.com/csrf-protection

Here's my current code to test registering an user:

        $response = $this->get('/register')
            ->assertStatus(200);

        $response = $this->json('POST', '/register', [
            'name' => 'Example Name',
            'email' => 'example@example.com',
            'password' => 'password',
            'password_confirmation' => 'password'
        ]);

        $response->assertCreated();

I 'm also not sure if this is the correct way to test a POST request from a form, so if this is wrong please suggest a better method to write a test for this, or if it is better to use Laravel Dusk to perform this kind of test by simulating the user filling out the form.

To find out it was a CSRF issue I ran:

$response->dump();

in the test.

Any suggestions are much appreciated.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!