1

My axios request (combined with Laravel) gives me a 500 error in the web console when I try to save a new question (= Frage):

"Error: Request failed with status code 500"

VueJS-method save():

save: function(){
    axios.post('/api/save-frage', this.Frage) //passes the object this.Frage
        .then(res => {
            // nothing here
            });
}

api.php:

Route::post('/save-frage','FragenController@store');

FragenController.php (Controller):

 public function store(Request $request)
    {
        // validation coming soon :)
        $frage = new Frage;
        $frage->Frage = request('Fragentext');
        $frage->save(); //if I comment this out, there's no error 500 :)
    }

Frage.php (Model):

<?php

    namespace App;

    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Support\Facades\Auth;

    class Frage extends Model
    {
        protected $table = 'fragen';
        protected $fillable = ['Frage']; // only field to fill is called "Frage"

    }

I thought maybe the route was wrong (api.php), but if I change this, I then get a 404 error, so I guess this is correct, since otherwise there would have always been a 404 error. Then I checked the model if maybe the table or fields were protected but this looks good to me. What am I doing wrong here?

5
  • 1
    So, can you show, what you have in $request? dd($request->all()) Commented Apr 25, 2020 at 19:43
  • 1
    status code 500 is a generic "catch-all" response. Check the /storage/logs/laravel.log file to see the error trace Commented Apr 25, 2020 at 19:44
  • 1
    Did you check web inspector, XHR tab? Commented Apr 25, 2020 at 19:54
  • Use Insomnia to debug it. It will point you out the error. Commented Apr 25, 2020 at 19:56
  • 1
    could you add your error from the response? you can find it in the network tab Commented Apr 25, 2020 at 20:04

1 Answer 1

1

Thanks guys, by looking in the XHR tab, as well as in laravel.log I saw the issue:

I reused an older table ("Frage") that

  1. didn't have the necessary "created_at" and "updated_at" columns.
  2. has lots of other columns beside "Frage" without a default value, that needed input as well.

My solution:

  1. add the missing two columns

  2. send the other column values in the this.Frage also.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.