php - axios 请求返回错误 500 (laravel, axios & vuejs)
问题描述
当我尝试保存新问题(= Frage)时,我的 axios 请求(与 Laravel 结合)在 Web 控制台中出现 500 错误:
"Error: Request failed with status code 500"
VueJS 方法保存():
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(控制器):
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 错误。然后我检查了模型是否可能表或字段受到保护,但这对我来说看起来不错。我在这里做错了什么?
解决方案
谢谢大家,通过查看 XHR 选项卡以及 laravel.log 我看到了这个问题:
我重用了一张旧表(“Frage”)
- 没有必要的“created_at”和“updated_at”列。
- 除了“Frage”之外还有很多其他没有默认值的列,也需要输入。
我的解决方案:
添加缺少的两列
也发送 this.Frage 中的其他列值。
推荐阅读
- oracle - Oracle APEX for BI Publisher 报告中的键值对 XML 生成
- javascript - 在 if 语句中声明或不声明函数的原因
- sql - BigQuery,用之前的非空值填充缺失值
- mysql - 用于处理“库存”详细信息 MySQL 的数据库表设计
- azure-devops - Azure DevOps 查询 - 显示我昨天参与的所有工作项
- php - 运行 php artisan 备份时出错:运行
- html - 在 qt 中使用 WTemplate 创建弹出菜单
- channel - 是否有任何用于 Houzz 集成的 api 参考或文档?
- assembly - 如果在程序执行时更改 GDT 会发生什么?
- java - Spring Boot Rest Web Service在获取请求中获取多个参数