I have 4 models.
- User
- Shipment
- Status
- Status history
User.php
public function shipments() {
return $this->hasMany('App\Shipment', 'from_user_id');
}
Shipment.php
public function statuses() {
return $this->hasMany('App\StatusHistory', 'model_id');
}
A User has many Shipment.
A Shipment has many Status instances through StatusHistory.
How can I get with an Eloquent relationship all the Shipment values for an User, that have a specific id value in the StatusHistory model?
whereHaswhen querying$user->shipments()->whereHas(...).