Laravel 500 (Internal Server Error) on POST request


Posted 6 years ago by Ryan Dhungel

Category: JavaScript React Laravel

Viewed 22996 times

Estimated read time: 2 minutes

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!