Eloquent: Calling Where on a relation

前端 未结 1 1023
你的背包
你的背包 2021-01-26 04:10

I have the following Eloquent ORM query.

$products2 = Product::with(\'metal\', \'metal.fixes\', \'metal.fixes.currency\')
    ->where(\'metal_id\', \'=\', 1)
         


        
相关标签:
1条回答
  • 2021-01-26 04:34

    You are looking for "Eager Load Constraints": http://laravel.com/docs/eloquent#querying-relations

    <?php
    $products2 = Product::with(array('metal', 'metal.fixes', 'metal.fixes.currency' => function($query){
        $query->where('currency_id', '=', 1);
    }))
    ->where('metal_id', '=', 1)
    ->get()->toArray();
    
    0 讨论(0)
提交回复
热议问题