title: Laravel 8 Jetstream Inertia All Inertia requests must receive a valid Inertia response
body: <p>I've been trying to find the correct answer for my problem I know that the question has been asked before <a href="https://stackoverflow.com/questions/65535729/all-inertia-requests-must-receive-a-valid-inertia-response-however-a-plain-json">here</a> and actually many other places, but no answers I found could suit my problem.</p>
  <p><strong>The vue component</strong></p>
  <pre><code>FooterNewsletter.vue
  
  &lt;template&gt;
      &lt;div class=&quot;lg:w-2/4 md:w-1/2 w-full px-8 border-l-2&quot;&gt;
          &lt;p class=&quot;font-bold text-3xl&quot;&gt;
              Don't want to miss the latest cryptocurrency news?
          &lt;/p&gt;
          &lt;p class=&quot;py-3 text-lg&quot;&gt;
              Get the latest news and updates by subscribing to our free
              newsletter 
          &lt;/p&gt;
          &lt;form @submit.prevent=&quot;subscribeToNewsletter&quot;&gt;
              &lt;div class=&quot;flex flex-col&quot;&gt;
                  &lt;div class=&quot;flex&quot;&gt;
                      &lt;input
                          v-model=&quot;form.email&quot;
                          type=&quot;text&quot;
                          name=&quot;post_title&quot;
                          class=&quot;
                              border-primary
                              focus:border-primary
                              focus:ring-offset-transparent
                              focus:ring-transparent
                          &quot;
                          id=&quot;exampleFormControlInput1&quot;
                          placeholder=&quot;Your E-mail&quot;
                      /&gt;
                      &lt;input
                          type=&quot;submit&quot;
                          value=&quot;Subscribe&quot;
                          :disabled=&quot;form.processing&quot;
                          class=&quot;px-5 py-2 bg-primary text-white cursor-pointer&quot;
                      /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
  
  export default {
      props: [],
      components: {
  
      },
      data() {
          return {
              form: this.$inertia.form({
                  email: &quot;&quot;,
              }),
          };
      },
      methods: {
          subscribeToNewsletter() {
              this.form
                  .transform((data) =&gt; ({
                      ...data,
                      // remember: this.form.remember ? &quot;on&quot; : &quot;&quot;,
                  }))
                  .post(this.route(&quot;newsletter.store&quot;), {
                      onSuccess: (data) =&gt; {
                          console.log(&quot;data&quot;, data);
                      },
                      onError: (data) =&gt; {
                          console.log(&quot;data&quot;, data);
                      },
                  });
          },
      },
  };
  &lt;/script&gt;
  </code></pre>
  <p><strong>The controller</strong></p>
  <pre><code>NewsletterController.php
  
  namespace App\Http\Controllers;
  
  use App\Http\Requests\NewsletterStoreRequest;
  use App\Models\Newsletter;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Redirect;
  
  class NewsletterController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {
          //
      }
  
      /**
       * Show the form for creating a new resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function create()
      {
      }
  
      /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function store(NewsletterStoreRequest $request)
      {
          return response()-&gt;json([
              'message' =&gt; 'suss',
          ]);
      }
  
      /**
       * Display the specified resource.
       *
       * @param  int  $id
       * @return \Illuminate\Http\Response
       */
      public function show($id)
      {
          //
      }
  
      /**
       * Show the form for editing the specified resource.
       *
       * @param  int  $id
       * @return \Illuminate\Http\Response
       */
      public function edit($id)
      {
          //
      }
  
      /**
       * Update the specified resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  int  $id
       * @return \Illuminate\Http\Response
       */
      public function update(Request $request, $id)
      {
          //
      }
  
      /**
       * Remove the specified resource from storage.
       *
       * @param  int  $id
       * @return \Illuminate\Http\Response
       */
      public function destroy($id)
      {
          //
      }
  }
  </code></pre>
  <p><strong>The request file</strong></p>
  <pre><code>NewsletterStoreRequest.php
  
  namespace App\Http\Requests;
  
  use Illuminate\Foundation\Http\FormRequest;
  
  class NewsletterStoreRequest extends FormRequest
  {
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          return true;
      }
  
      /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
      public function rules()
      {
          return [
              'email' =&gt; ['required', 'max:150', 'email'],
          ];
      }
  }
  </code></pre>
  <p><strong>The Route</strong></p>
  <pre><code>web.php
  
  Route::post('/newsletter', [
      NewsletterController::class,
      'store',
  ])-&gt;name('newsletter.store');
  </code></pre>
  <p>In the sample above i return a json object, which is not accepted and gives me this error
  <a href="https://i.stack.imgur.com/6je6b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6je6b.png" alt="enter image description here" /></a></p>
  <p>I have tried following the inertia documentation about responses <a href="https://inertiajs.com/responses" rel="nofollow noreferrer">here</a> I think the correct answer is to be found there, I have not been able to solve it on my own</p>
  <p>I have also looked into inertia Jetstream docs without any luck <a href="https://jetstream.laravel.com/1.x/stacks/inertia.html#form-validation-helpers" rel="nofollow noreferrer">here</a></p>
  <p>I don't want to return a new view, I actually want it to work as an ajax request I guess where a call-back is either giving me the error or success without reloading the page or anything like that.</p>
  <p>I see that many people have this problem, does anyone know whats going wrong and what i have to return in the controller?</p>