我正在 Laravel 中创建一个项目。在 updatepackage.blade.php
中,用户选中了一个复选框。然后将复选框行值存储到数据库中并发送到另一个名为 printpackage.blade.php
的 View 。
问题从这里开始。当用户刷新页面时,条目中显示的值会自动插入到数据库中。我不知道如何阻止它。
updatepackage.blade.php
<td align='center'>{{$i}}</td>
<td><input type='text' name="meter[]" readonly value="{{$item['passmts']}}" ></td>
<td><input type='text' name="points[]" readonly value="{{$item['points']}}"></td>
<td><input type='text' name="pts[]" readonly value="{{$item['pts']}}"></td>
<td><input type="checkbox" name="ids[]"value="{{$i}}" /></td>
clientcontroller.php
$insert=DB::table('packageroll')->insert(array(Input::all()));
$tc=\Input::get('tc');
$construction=\Input::get(construction');
$table1= DB::table('packageroll')->where('tc','=',$tc)->where('construction','=',$construction)->get();
return \View::make('dashboard.vendor.printpackage')->with('table1',$table1);
printpackage.blade.php
<td><input type='text' name='meter[]' value="{{$item['meter']}}" ></td>
<td><input type='text' name='points[]' value="{{$item['points']}}"></td>
<td><input type='text' name='pts[]' value="{{$item['pts']}}"></td>
最佳答案
嘿,你可以对 store 和 update 使用不同的验证,如果你有独特的值(value),我在下面提到了如何处理
public function store(Request $request)
{
$this->validate($request, ['code'=>'required|unique:consignees,''=>'',''=>'']);
}
public function update(Consignee $consignee,Request $request)
{
$this->validate($request,['code'=>'required|unique:consignees,code,'.$consignee->id,''=>'',''=>'']);
}
关于php - 如何阻止 Laravel 在页面刷新时将数据插入数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35193601/