Ad
Access Index Of Pivot Table In Laravel
Is there a way that i can Access pivot table like below???
array:18 [
"id" => 4
"user_id" => 5
"price" => 8659
"created_at" => "2020-01-17 14:08:06"
"updated_at" => "2020-01-17 14:08:06"
"pivot" => array:5 [
"purchase_id" => 6
"product_id" => 4
"quantity" => "13"
"unit_price" => "3212"
"discount" => "11.00"
]
]
I want to Update Pivot
Table and i tried method like below
foreach($request->products as $product) {
$purchase->products()->updateExistingPivot($product['id'], [
'unit_price' => $product['unit_price'],
'quantity' => $product['quantity'],
'discount' => $product['discount'],
]);
// dd($product);
}
But got an error message: "Undefined index: unit_price"
.
Any Help, Thanks in Advance...
Ad
Answer
It seems you don't have unit_price
key in your $product
,
Try to call it by $product['pivot']
$purchase->products()->updateExistingPivot($product['id'], [
'unit_price' => $product['pivot']['unit_price'],
'quantity' => $product['pivot']['quantity'],
'discount' => $product['pivot']['discount'],
]);
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad