hasOneThrough Last updated: 2022-10-01
Sometimes you need to fetch a single value 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 hasOneThrough
We will clarify more
We have products and we have orders
This product was purchased by the user, but you want to place one 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
hasOneThrough()->make('first order', 'order',OrdresResource::class)
Note that we have linked requests with the user and set the link method is order
public function order() {
return $this->hasOneThrough(
Order::class ,
Product::class ,
);
}
That's it