I have 3 table Orders , Orderdetails and products table every order is unique and every order have multiple orderdetail with order id and every orderdetail has product_id
I am using a foreach loop in blade
@foreach($order->orderdetail as $odetail)
<tr>
<td><input type="number" value="{{ $odetail->amount }}" ></td>
</tr>
@endforeach
this value="{{ $odetail->amount }}" gets value 25 in input field
i have another foreach loop
@foreach($products as $key => $p)
<tr>
<td><input type="number" value="{{ $p->order->orderdetail->unit }}"></td>
</tr>
@endforeach
i want that above loop value="{{ $odetail->amount }}" output in 2nd foreach loop so i try this
value="{{ $p->order->orderdetail->unit }}"
if orderdetail gets value in first loop then why it is not getting value in 2nd foreach loop can someone clear me what is mistake and how doeas model works and how i can get value in 2nd loop?
here is my Order model class and orderdetail function
class Order extends Model
{
public function orderdetail(){
return $this->hasMany('App\OrderDetail','order_id');
}
}
and here is my orderdetail class and functions
class OrderDetail extends Model
{
public function order(){
return $this->belongsTo('App\Order');
}
public function product(){
return $this->belongsTo('App\Product');
}
}
here it is product model
class Product extends Model
{
public function category(){
return $this->belongsTo('App\Category');
}
}
databse image of orderdetai enter image description here
dd($products)and see the records over there