LoginSignup
0
0

More than 3 years have passed since last update.

Laravel hasManyThrough メモ

Posted at

決済情報テーブル

id user_id 決済情報2
1 1 hoge1
2 2 hoge2

中間テーブル(購入した商品と購入者)

id アイテム_id 決済情報_id
1 1 1
2 1 2
3 2 2

商品テーブル

id 商品名 商品説明
1 huga1 huga1
2 huga2 huga2
class Settlement extends Model
{
  
    public function getItems()
    {
        return $this->hasManyThrough(商品::class, 中間::class, '決済情報_id', 'id', null, '商品_id');
    }
}

Settlement::with('getItems')->where('user_id', Auth::id())->get();

とかとかで、購入ユーザーごとの購入商品の情報が商品テーブルから取得できる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0