I manage to create the correct relations from products to each treatment.
What I cannot figure out is how to relate the prescription to the product in the corresponding treatment. A product can belong to many treatments.
If I use a normal pivot table for products_prescription, then this relation applies to all treatments. This should not be the case.
How should I setup the relationship, so I'm able to use this in blade?
@foreach ($treatment->products as $product)
{{ $product->name }} {{ $product->prescription->amount }}
@endforeach
How create nested relationship over three models
Hello
I'm completely new to Laravel and have the following situation:
I have the following Models:
Treatments can have many Products. Each associated Product to a Treatment can have a unique Prescription.
The tables are:
I manage to create the correct relations from products to each treatment. What I cannot figure out is how to relate the prescription to the product in the corresponding treatment. A product can belong to many treatments. If I use a normal pivot table for products_prescription, then this relation applies to all treatments. This should not be the case.
How should I setup the relationship, so I'm able to use this in blade? @foreach ($treatment->products as $product) {{ $product->name }} {{ $product->prescription->amount }} @endforeach
Thanks a lot for any hint or help. Aldo