laravel hasmanythrough example
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
public function orders()
{
return $this->hasManyThrough(
'App\Order',
'App\Product',
'category_id', // Foreign key on products table...
'product_id', // Foreign key on orders table...
'id', // Local key on categories table...
'id' // Local key on products table...
);
}
}
// full answer is in source: https://xpertphp.com/laravel-hasmanythrough-eloquent-relationship-tutorial-example/