你好这是我的laravel控制器,我在这里没有遇到问题。如果我手动输入值为1的数据集,它会检查文件,但是如果我使用系统执行此操作,则不会更新该值,并且未选中框时该框保持为0。
我想要做的是勾选方框,如果用户勾选它并保持方框勾选,直到他勾选它再加上数据库值。提前谢谢
public function tickoffUpload($id, $type, User $user) {
$uploads = $this->upload->get($id);
// if($this->request->isMethod('get')) {
// if($user->can('untick', $uploads)) {
// $uploads = $this->upload = 0;
// } else {
// return $uploads = $this->upload = 1;
// }
// }
if($this->request->isMethod('get')) {
if($type == 0) {
$uploads = $this->upload = 1;
} else if($type == 1){
$uploads = $this->upload = 0;
}
}
if(isset($_POST["uploaded"]) && !empty($_POST["uploaded"])) {
$uploads->uploaded = $this->request->uploaded;
$uploads->save();
}
return redirect('/home');
}
答案 0 :(得分:0)
我把它排除了。我没有从表单中获取请求值,正如您在此处看到的$uploads->uploaded = $this->upload = 1;
所以这里是我所做和更新的代码。
public function tickoffUpload($id, $type, User $user) {
$uploads = $this->upload->get($id); //gets upload id
// requesting uploaded value either 0 or 1
if($this->request->isMethod('get')) {
if($type == 0) {
$uploads->uploaded = $this->request->upload = 1;
} else if($type == 1) {
$uploads->uploaded = $this->request->upload = 0;
}
}
$uploads->save(); // saving the value in database
return redirect('/home');
}
感谢d3r1ck
寻求帮助,但是...... :)