php - 如何阻止 Laravel 在页面刷新时将数据插入数据库?

标签 php laravel laravel-blade

我正在 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> 

最佳答案

嘿,你可以对 storeupdate 使用不同的验证,如果你有独特的值(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/

相关文章:

javascript - 将两个 javascript 合并为一个 foreach

php - 如何在mysql中存储以逗号分隔的文本

PHP PDO简单插入或更新函数

php - 在 Laravel 一对多关系上插入数据失败

php - 无法让 Beautymail 为 Laravel 5.2 工作

php - 拉维尔 : How to send variable from one page to another in blade

php - header 由 Apache 接收,但不存在于 php 中

php - 我想运行查询来获取 catagory_name 的层次结构

php - 如何使用 Laravel/PHP 和 MySQL 高效地将数组插入为嵌套集模型

php - 我怎样才能理顺 Laravel blade @extends 的执行顺序?