英文:
Insert multiple value laravel
问题
你的代码在Controller中似乎只插入了nama_menu
的一个值。如果你希望从View Blade中插入多个nama_menu
值,你可以将这些值存储为一个数组,然后在Controller中进行处理。以下是一种可能的修改方法:
在View Blade中,使用一个数组来存储多个nama_menu
值:
@foreach($fi as $z)
<input type="hidden" value="{{$z->name}}" name="nama_menu[]" id="nama_menu">
<input type="hidden" value="{{$z->quantity}}" name="jumlah[]" id="jumlah">
<input type="hidden" value="{{$z->price * $z->quantity}}" name="total_pembayaran[]" id="total">
@endforeach
在Controller中,处理这些数组并插入多个记录:
public function store(Request $r){
$nama_menu = $r->input('nama_menu');
$jumlah = $r->input('jumlah');
$total_pembayaran = $r->input('total_pembayaran');
// 假设这些数组具有相同的长度,你可以使用循环来插入多个记录
for ($i = 0; $i < count($nama_menu); $i++) {
$history = new History();
$history->nama = $r->nama;
$history->provinsi = $r->provinsi;
$history->nama_menu = $nama_menu[$i];
$history->jumlah = $jumlah[$i];
$history->kota = $r->kota;
$history->total_pembayaran = $total_pembayaran[$i];
// 插入其他字段
$history->save();
}
return redirect(url('/checkout'))->with(['success' => 'berhasil mengirim pesan whatsapp']);
}
这样,你的Controller会根据数组中的值插入多个记录,每个记录都包含不同的nama_menu
值。
英文:
Hello i want insert multiple value in nama_menu
My Code In Controller
public function store(Request $r){
$history = new History();
$history->nama = $r->nama;
$history->provinsi = $r->provinsi;
$history->nama_menu = $r->nama_menu;
$history->jumlah = $r->jumlah;
$history->kota = $r->kota;
$history->total_pembayaran = $r->total_pembayaran;
$history->status = $r->status;
$history->kecamatan = $r->kecamatan;
$history->kelurahan = $r->kelurahan;
$history->kodepos = $r->kodepos;
$history->address = $r->address;
$history->whatsapp = $r->whatsapp;
$history->jenis_pembayaran = $r->jenis_pembayaran;
$history->save();
return redirect(url('/checkout'))->with(['success' => 'berhasil mengirim pesan whatsapp']);;
}
My View Blade
` <div class="cart-page-heading">
<h5>Orderan Kamu</h5>
<p>The Details</p>
</div>
<ul class="order-details-form mb-4">
<li><span>Product</span><span>Jumlah</span> <span>Total</span></li>
@foreach($fi as $z)
<input type="hidden" value="{{$z->name}}" name="nama_menu" id="nama_menu">
<input type="hidden" value="{{$z->quantity}}" name="jumlah" id="jumlah">
<input type="hidden" value="{{$z->price * $z->quantity}}" name="total_pembayaran" id="total">
<li><span>{{$z->name}}</span ><span>{{$z->quantity}}</span> <span>Rp. {{($z->price * $z->quantity)}}</span></li>
@endforeach
<li><span>Total</span> <span>Rp. {{ Cart::getTotal() }}</span></li>
</ul>
`
when i insert the data only nama_menu show one value
insert fieled
i want nama_menu insert many viewbladevalues from view blade
答案1
得分: 0
convert into an array or comma-separated value. it possible way. after that used to implode and explode functions in PHP
英文:
convert into an array or comma-separate value. it possible way. after that used to implode and explode functions in PHP
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论