How to access model hasMany Relation with where condition?

前端 未结 8 1379
迷失自我
迷失自我 2020-12-08 00:02

I created a model Game using a condition / constraint for a relation as follows:

class Game extends Eloquent {
             


        
8条回答
  •  一个人的身影
    2020-12-08 00:36

    If you want to apply condition on the relational table you may use other solutions as well.. This solution is working from my end.

    public static function getAllAvailableVideos() {
            $result = self::with(['videos' => function($q) {
                            $q->select('id', 'name');
                            $q->where('available', '=', 1);
                        }])                    
                    ->get();
            return $result;
        }
    

提交回复
热议问题