Laravel 500 (Internal Server Error) on POST request


Posted 3 months ago | by Ryan Dhungel | on JavaScript React Laravel  | Viewed 609 times

Have you been getting 500 Internal Server Error in your Laravel project every time you make a POST request from JavaScript side of your application using Vue JS or React JS?

There might be three possible reasons

  • You are not using the correct post route
  • You have not set the protected fillable fields in your model
  • You are not sending all required fields for example title and body

Possible solutions

Make sure you are using post route such as Route::post(‘/blogs’);

Set the fillable fields, for example here on my Blog model, I have set these fields fillable:

protected $fillable = ['title', 'body'];

Send all the required fields in your post request. Here I have send the title and body as POST request from react component using axios

        axios
            .post('/blog/store', {
                title: this.state.title,
                body: this.state.body
            })
            .then(response => {
                console.log('from handle submit', response);
            });

you can also try setting mysql strict mode to false in config/database.php and see what happens:

'strict' => false,

It changing strict to false fixes the issue, then you are not sending all the fields on your post request.

Easy debugging:

When you make such GET or POST request from JavaScript side of your application, always open the network tab in the google chrome console and click on the post link that appears. Click on that link and click on Preview tab to see the error messages etc.

Hope you were able to pass through your error messages. If so.. congrats!



Specials


Build Laravel React CRUD/SPA APP in 2 hours
Build Laravel React CRUD/SPA APP in 2 hours

Build Laravel React CRUD/SPA APP in 2 hours

COUPON CODE: REACTCRUD with 90% off


Laravel with React JS - Build Twitter Like Real Ti...
Laravel with React JS - Build Twitter Like Real Time Web App

Laravel with React JS - Build Twitter Like Real Time Web App

COUPON CODE: LARAVELREACT with 90% off


Learn Laravel Building Multi User Blogging Platfor...
Learn Laravel Building Multi User Blogging Platform with SEO


React Redux Firebase CRUD App with Authentication
React Redux Firebase CRUD App with Authentication

React Redux Firebase CRUD App with Authentication

COUPON CODE: RRFTEN with 86% off


Become a Master of JavaScript from Scratch in 2018
Become a Master of JavaScript from Scratch in 2018

Become a Master of JavaScript from Scratch in 2018

COUPON CODE: JSMASTERSALE with 92% off


REACT - Up and Running with React ES6 and Open Sou...
REACT - Up and Running with React ES6 and Open Source API


Sublime Text for Rapid Web Development
Sublime Text for Rapid Web Development

Sublime Text for Rapid Web Development

COUPON CODE: LEARNSUBLIME with 90% off