Laravel whereHas on multiple relationships

后端 未结 3 1537
庸人自扰
庸人自扰 2020-12-25 15:45

Does anyone know if this new feature can be performed on multiple relationships?

For example, I have a query where I want to filter on not only the club name (relate

3条回答
  •  借酒劲吻你
    2020-12-25 16:00

    I don't think you need 'with' as there is 'wherehas'

    Model::whereHas('territory',function( $query ){
            $query->where('region','Australia');
        })->whereHas('homeClub', function ( $query ) {
            $query->where('name', 'Arsenal' );
        })->orWhereHas('awayClub', function ( $query ) {
            $query->where('name', 'Arsenal' );
        });
    

提交回复
热议问题