This is my schema as follows:
Medicines
- id
- price
- description
- etc..
Ecommerce Orders(has many Medicines)
- id
- user_id
- products (array that holds the id's of the medicine's and quantity)
And in my EcommerceOrders Model i have
protected $casts = [
'products' => 'array',
];
public function items()
{
return $this->hasMany(Medicines::class,'id','products')->withTrashed();
}
What I'm trying to do is to create a relationship between ecommerceOrders and medicines so when i get the data of an order that a client has made i also get the data of the products he has orederd How can i do this with the foreign key in this instance being an array