当我尝试保存新问题(= Frage)时,我的axios请求(与Laravel结合使用)在Web控制台中给我500错误:"Error: Request failed with status code 500"
VueJS方法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(模型):<?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"
}
我以为路线可能是错误的(api.php),但是如果我更改此路线,则会收到404错误,因此我认为这是正确的,因为否则始终会出现404错误。然后,我检查了模型是否对表或字段进行了保护,但这对我来说很好。我在这里错了吗?