Reputation: 510
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?
Upvotes: 1
Views: 492
Reputation: 510
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
My solution:
add the missing two columns
send the other column values in the this.Frage also.
Upvotes: 1