if($aa){
$response = [
'status' => 0,
'msg' => '写入成功',
];
}esle{
$response = [
'status' =>1,
'msg' => '写入失败',
];
}
return response()->json($response, 200);
以上是针对你的代码写的API JSON返回信息
@Small_Tree public function aa(){
$aa = Channel::create([
'Pname' => 'as45',
'Code' => '97',
'Cnname' => '97',
]);
if($aa){
$response = [
'status' => 0,
'msg' => '写入成功',
];
}else {
$response = [
'status' => 1,
'msg' => '写入失败',
];
}
return response()->json($response, 200);
}
修改成如下试试
public function aa(){
$data = [
'Pname' => 'as45',
'Code' => '97',
'Cnname' => '97'
];
$aa = Channel::insert($data);
if($aa){
$response = [
'status' => 0,
'msg' => '写入成功',
];
}else {
$response = [
'status' => 1,
'msg' => '写入失败',
];
}
return response()->json($response, 200);
}
@Small_Tree 还是插入两次
$data = [
'Pname' => 'as45',
'Code' => '123',
'Cnname' => '123'
];
$aa = Channel::insert($data);
if($aa){
$response = [
'status' => 0,
'msg' => '写入成功',
];
}else {
$response = [
'status' => 1,
'msg' => '写入失败',
];
}
return response()->json($response, 200);
推荐文章: