[英]Creating a record to laravel databse with vue.js doesn't work
I'm trying to create a new record to my database using Vue.js in laravel, my API, data is okay.我正在尝试在 laravel、我的 API、数据中使用 Vue.js 为我的数据库创建一个新记录。 But I get that strange error when I click create on my site.但是当我在我的网站上点击创建时,我得到了那个奇怪的错误。
Argument 1 passed to Illuminate\\Database\\Grammar::parameterize() must be of the type array, string given, called in C:\\Users\\PC\\Desktop\\Productivity\\gitdemo\\students\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Query\\Grammars\\Grammar.php on line 884传递给 Illuminate\\Database\\Grammar::parameterize() 的参数 1 必须是数组类型,给定字符串,在 C:\\Users\\PC\\Desktop\\Productivity\\gitdemo\\students\\vendor\\laravel\\framework\\src\\Illuminate 中调用\\Database\\Query\\Grammars\\Grammar.php 第 884 行
I also have delete function that works perfectly, but this doesn't work... Form inputs have v-model
, that seems alright, but it still doesn't work.我也有完美运行的删除功能,但这不起作用......表单输入有v-model
,这看起来没问题,但它仍然不起作用。
My create method on vue.js我在 vue.js 上的 create 方法
addStudent() {
axios.post(`api/students/create`, {data:this.students});
}
Getting records in vue.js在 vue.js 中获取记录
data() {
return{
students: [],
}
},
created() {
axios.get(`api/students`).then(response =>{
this.students = response.data.data;
})
},
Controller控制器
public function store(Request $request)
{
Student::create($request->all());
return view('welcome');
}
Route (in api.php)路由(在 api.php 中)
Route::post('students/create', 'StudentController@store');
Student Model学生模特
use SoftDeletes;
protected $dates = ['birth_date'];
protected $guarded = [];
Students array in data has all of the v-model
namings数据中的学生数组具有所有的v-model
命名
You should not directly pass $request->all()
to create method.你不应该直接通过$request->all()
来创建方法。 Based on what you send from front end to back end, do this:根据您从前端发送到后端的内容,执行以下操作:
$r = $request->all();
$students = $r['data'];
Student:create($students);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.