如何解决在laravel中存储数组值
我要存储表单数组值。但它提供了一些错误,请帮忙
接收错误
SQLSTATE [23000]:违反完整性约束:1048列'product_name'不能为空(SQL:插入bill_products
(product_name
,bill_no
,suppliers_master_id
,{ {1}},suppliers_unic_id
,party_id
,supplier_name
,GSTIN
,bill_date
,bill_entry_date
,qty
,{{1 }},HSN_SAC
,sale_rate
,MRP_rate
,purchase_rate
,part_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 举报,一经查实,本站将立刻删除。