I want to get id and name from select option for insert in table
how do I get that?
My view blade :
<th>
<select name="itemIdSelected" id="itemNameSelected" class="form-control nameItem" >
<option value="0" disabled="true" selected="true" >Select Item Name</option>
@foreach($listItem as $item)
<option value="{{ $item->item_id }}:{{$item->item_name}}">{{ $item->item_name }}</option>
@endforeach
</select>
</th>
My controller :
public function storeOrder(Request $request){
$order = DB::table('order_item_master_model')->insert([
'product_id' => $request -> itemIdSelected, // will return 15:Ben Top Biru, how do I get 15
'customer_name' => $request -> customerName,
'phone' => $request -> phone,
'address' => $request -> address,
'item_name' => $request -> itemIdSelected, // will return 15:Ben Top Biru, how do I get Ben Top Biru
'qty' => $request -> qty,
'uom' => $request -> uom,
'item_price' => $request -> prc,
'total_price' => $request -> totalPrice,
'status' => $request -> status,
]);
return redirect('orderProcess');
Here is my error :
IlluminateDatabaseQueryException
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'product_id' at row 1 (SQL: insert into order_item_master_model
(product_id
, customer_name
, phone
, address
, item_name
, qty
, uom
, item_price
, total_price
, status
) values (15:Ben Top Biru, dana, 081233, purwojersey, 15:Ben Top Biru, 2, Liter, Rp. 4000, Rp. 8000, lunas))
How do I solve this error
question from:
https://stackoverflow.com/questions/65887491/how-to-explode-select-option-id-and-name-in-store-method-laravel-controller 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…