hasManyThrough Last updated: 2022-10-01
Sometimes you need to fetch a multiple values through a model that you did not associate with the user, but it is linked to this model with the same model you are targeting
Of course here you will use hasManyThrough
We will clarify more
We have products and we have orders
This product was purchased by the user, but you want to place multiple order through this user
Or you want to bring the last purchase of this product by this user based on the product number
So see this example to start using it with dash project
hasManyThrough()->make('all orders', 'orders',OrdresResource::class)
Note that we have linked requests with the user and set the link method is orders
public function orders() {
return $this->hasManyThrough(
Order::class ,
Product::class ,
);
}
That's it