PHP可以用axios请求吗,php - Axios请求返回错误500(laravel,axios和vuejs) - SO中文参考 - www.soinside.com...

当我尝试保存新问题(= 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错误。然后,我检查了模型是否对表或字段进行了保护,但这对我来说很好。我在这里错了吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值