在laravel中存储数组值

如何解决在laravel中存储数组值

我要存储表单数组值。但它提供了一些错误,请帮忙

接收错误

SQLSTATE [23000]:违反完整性约束:1048列'product_name'不能为空(SQL:插入bill_productsproduct_namebill_nosuppliers_master_id,{ {1}},suppliers_unic_idparty_idsupplier_nameGSTINbill_datebill_entry_dateqty,{{1 }},HSN_SACsale_rateMRP_ratepurchase_ratepart_no)值(?,111w,master_5499384803,unic_5764728886,PARTY-NO922826,dvfd,fg99 ,06-08-2020,15-08-2020,1,1,11,1,1,1,2020-08-15 16:24:28,2020-08-15 16:24:28)) 这是我的控制器

updated_at

这是我的控制器

created_at

这是我的观点

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'product_name' cannot be null (SQL: insert into `Item_list`  

这是我的路线

public function purchaseentryformsave(Request $request)
   {
   
       $purchasen=new Purchase;
       $purchasen->supplier_name       = $request->supplier_name;
       $purchasen->bill_no             = $request->bill_no; 
       $purchasen->suppliers_master_id = $request->suppliers_master_id; 
       $purchasen->party_id            = $request->party_id; 
       $purchasen->GSTIN               = $request->GSTIN; 
       $purchasen->bill_date           = $request->bill_date; 
       $purchasen->bill_entry_date     = $request->bill_entry_date; 
       $purchasen->total_bill_amount   = $request->total_bill_amount; 
       $purchasen->phone               = $request->phone; 
       $purchasen->pincode             = $request->pincode; 
       $purchasen->state               = $request->state; 
       $purchasen->address             = $request->address;
       $purchasen->suppliers_unic_id   = $request->suppliers_unic_id;

      if ($purchasen->save()){

        $product_name        = $purchasen->product_name;
        $bill_no             = $purchasen->bill_no;
        $suppliers_master_id = $purchasen->suppliers_master_id;
        $suppliers_unic_id   = $purchasen->suppliers_unic_id;
        $party_id            = $purchasen->party_id;
        $supplier_name       = $purchasen->supplier_name;
        $GSTIN               = $purchasen->GSTIN;
        $bill_date           = $purchasen->bill_date;
        $bill_entry_date     = $purchasen->bill_entry_date;
        
 foreach($request->qty as $k => $p){
       Billproduct::create([
           'product_name'        => $product_name,'bill_no'             => $bill_no,'suppliers_master_id' => $suppliers_master_id,'suppliers_unic_id'   => $suppliers_unic_id,'party_id'            => $party_id,'supplier_name'       => $supplier_name,'GSTIN'               => $GSTIN,'bill_date'           => $bill_date,'bill_entry_date'     => $bill_entry_date,'qty'                 => $request['qty'][$k],'HSN_SAC'             => $request['HSN_SAC'][$k],'sale_rate'           => $request['sale_rate'][$k],'MRP_rate'            => $request['MRP_rate'][$k],'purchase_rate'       => $request['purchase_rate'][$k],'part_no'             => $request['part_no'][$k],]);
     }


 foreach($request->qty as $g => $p){
   Item_list::create([
       'supplier_name'       => $supplier_name,'product_name'        => $product_name,'qty'                 => $request['qty'][$g],'purchase_rate'       => $request['purchase_rate'][$g],'MRP_rate'            => $request['MRP_rate'][$g],'sale_rate'           => $request['sale_rate'][$g],'part_no'             => $request['part_no'][$g],]);
 }
}

    return back()->with('success',' NEW PURCHASE ADDED SUCCESSFULLY .');
  
}

我的模特 Billproduct

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">PURCHASE FORM</div>

                <div class="card-body">
            
                @if (Session::has('success'))
                    <div class="alert alert-success">{!! Session::get('success') !!}</div>
                @endif
                @if (Session::has('failure'))
                    <div class="alert alert-danger">{!! Session::get('failure') !!}</div>
                @endif
                    
                           

                     
          <form method="POST"   action="{{route('purchaseentryformsave')}}" enctype="multipart/form-data">

            @csrf

            <input type="text"style="background-color:yellow ;"  class="form-control "  name="suppliers_master_id"  placeholder="SUPPLIER NAME" value="{{ $Supplierdata->suppliers_master_id }}" hidden>

            <input type="text"style="background-color:yellow ;"  class="form-control "  name="suppliers_unic_id"  placeholder="SUPPLIER NAME" value="{{ $Supplierdata->suppliers_unic_id }}" hidden>

            <input type="text"style="background-color:yellow ;"  class="form-control "  name="GSTIN"  placeholder="SUPPLIER NAME" value="{{ $Supplierdata->GSTIN }}" hidden>


            <input type="text"style="background-color:yellow ;"  class="form-control "  name="phone"  placeholder="SUPPLIER NAME" value="{{ $Supplierdata->phone }}" hidden>

            <input type="text"style="background-color:yellow ;"  class="form-control "  name="pincode"  placeholder="SUPPLIER NAME" value="{{ $Supplierdata->pincode }}" hidden>

            <input type="text"style="background-color:yellow ;"  class="form-control "  name="state"  placeholder="SUPPLIER NAME" value="{{ $Supplierdata->state }}" hidden>

            <input type="text"style="background-color:yellow ;"  class="form-control "  name="address"  placeholder="SUPPLIER NAME" value="{{ $Supplierdata->address }}" hidden>


      





      
  <div class="form-row">

    <div class="col-md-4 mb-3">
      <label for="validationServer01">SUPPLIER NAME</label>
      <input type="text"style="background-color:yellow ;"  class="form-control "  name="supplier_name" id="validationServer01" placeholder="SUPPLIER NAME" value="{{ $Supplierdata->supplier_name }}" required >
      
    </div>

  <div class="col-md-2 mb-3">
      <label for="validationServer01">PARTY-NO</label>
      <input type="text" style="background-color:yellow ;"  class="form-control"   name="party_id" id="validationServer01" placeholder="PARTY-NO" value="{{ $Supplierdata->party_id}}" required >
      
    </div>




 <div class="col-md-2 mb-3">
      <label for="validationServer01">BILL DATE</label>
      <input type=" " class="form-control "  name="bill_date" id="date" placeholder="BILL DATE" value="" required  >
      
    </div>

      <div class="col-md-2 mb-3">
      <label for="validationServer01">BILL ENTRY DATE</label>
      <input type="" class="form-control "  name="bill_entry_date"  placeholder="BILL DATE" value="<?php echo date('d-m-yy'); ?>" required>
      
    </div>

 

  <div class="col-md-2 mb-3">
      <label for="validationServer01">BILL NO</label>
      <input type="text" class="form-control "  name="bill_no" id="validationServer01" placeholder="BILL NO" value="" required >
      
    </div>

  </div>

 

  <div class="form-row">
 
 
<style>
table,th,td {
  border: 1px solid black;
  border-collapse: collapse;
}
th,td {
  padding: 5px;
  text-align: left;    
}
</style>
<style>
  table thead { display:block; }
  table tbody { height:250px; overflow-y:scroll; display:block; }
  </style>
  </div>

  
<table id="tableAppointment" style="background-color:powderblue;">
 
    <tr>
    <th style="text-align:center;" colspan="1">Description of Goods</th>
    <th style="text-align:center;" colspan="1">HSN/SAC</th>
    <th style="text-align:center;" colspan="1">MRP</th>
    <th style="text-align:center;" colspan="1">Part No</th>
    <th style="text-align:center;" colspan="1">Qty</th>
    <th style="text-align:center;" colspan="1">GST</th>
    <th style="text-align:center;" colspan="1">Rate</th>
    <th style="text-align:center;" colspan="1">Sale Rate</th>
    <th style="text-align:center;" colspan="1">Amout</th>
  </tr>
   
   <tr>
    <td ><input style="text-align:center;" type="text" class="text-danger   form-control "  name="product_name[]" id="validationServer01" placeholder="Item" value="" required  autocomplete="off" ></td>

    <td ><input  style="text-align:center;" type="text" class="text-danger input-lg form-control "  name="HSN_SAC[]" id="validationServer01" placeholder="HSN/SAC" value="" required   autocomplete="off"></td>
    
    <td > <input  style="text-align:center;" type="text" class="form-control "  name="MRP_rate[]" id="validationServer01" placeholder="MRP" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control "  name="part_no[]" id="validationServer01" placeholder="PART-NO" value="" required  autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control quantity"  name="qty[]" id="validationServer01" placeholder="QTY" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control gst "  name="gst_amount[]" id="validationServer01" placeholder="GST" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control price"  name="purchase_rate[]" id="validationServer01" placeholder="RATE" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control "  name="sale_rate[]" id="validationServer01" placeholder="Sale Rate" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control totalamount"  name="" id="validationServer01" placeholder="AMOUNT" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" disabled></td>
  </tr>

     <tr>
    <td ><input style="text-align:center;" type="text" class="text-danger   form-control "  name="product_name[]" id="validationServer01" placeholder="Item" value="" required  autocomplete="off" ></td>
    <td ><input  style="text-align:center;" type="text" class="text-danger input-lg form-control "  name="HSN_SAC[]" id="validationServer01" placeholder="HSN/SAC" value="" required   autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="form-control "  name="MRP_rate[]" id="validationServer01" placeholder="MRP" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control "  name="part_no[]" id="validationServer01" placeholder="PART-NO" value="" required  autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control quantity"  name="qty[]" id="validationServer01" placeholder="QTY" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control gst "  name="gst_amount[]" id="validationServer01" placeholder="GST" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control price"  name="purchase_rate[]" id="validationServer01" placeholder="RATE" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control "  name="sale_rate[]" id="validationServer01" placeholder="Sale Rate" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" autocomplete="off"></td>
    <td > <input  style="text-align:center;" type="text" class="text-danger  input-lg form-control totalamount"  name="" id="validationServer01" placeholder="AMOUNT" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+"numbers="onlynumbers" disabled></td>
  </tr>
 
 
</table>
<br>


  <div class="row justify-content-between">
     <div class="text-danger  col-md-2 offset-md-10">
    <b>VALVE OF GOODS</b>
       
    </div>
  </div>

<div class="row justify-content-between">
   <div class="col-md-2 offset-md-10"> <input type="text" class=" text-danger  form-control total"  name="total_bill_amount" id="validationServer01" placeholder=" VALVE OF GOODS"  required >
   </div>
 
                           
</div>
  <hr>
 
  <button class="btn btn-primary float-right" type="submit">SAVE</button>
</form>

 <a style='margin-right:40px' class="btn btn-secondary float-right" href="{{ route('allpurchasesupplierlist') }}" role="button">BACK</a>
                </div>
            </div>
        </div>
    </div>
</div>

我的模特 ** Item_list **

 Route::get('purchaseentryform{id}','PurchaseController@purchaseentryform')->name('purchaseentryform');
 Route::post('purchaseentryformsave','PurchaseController@purchaseentryformsave')->name('purchaseentryformsave');

我的模特 **购买**

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Billproduct extends Model
{
     
     protected $table = 'bill_products';
     protected $fillable = ['supplier_name','suppliers_master_id','suppliers_unic_id','GSTIN','party_id','bill_no','bill_entry_date','bill_date','product_name','qty','purchase_rate','MRP_rate','supplier_name','sale_rate','HSN_SAC','part_no'];
}

解决方法

您应在ChangeDetectorRef之前添加$purchasen->product_name = $request->product_name;

if ($purchasen->save())

然后

$purchasen=new Purchase;
$purchasen->product_name = $request->product_name;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-