php - How to select models where all relations have a specific property set to a specific value with Laravel? -
normally, i'm dealing queries have 2 models , need select 1 model wherehas
query, greedy condition selects many matches possible.
here 2 models:
class part extends eloquent { protected $table = 'parts'; protected $primarykey = 'part_id'; public function partflights() { return $this->hasmany('partflights'); } }
and
class partflight extends eloquent { protected $table = 'part_flights_pivot'; protected $primarykey = 'part_flight_id'; public function part() { return $this->belongsto('spacecraft'); } }
as can see, there's 1:m relationship between part
, partflight
.
what want non-greedy match select part
's partflight
's have attribute landed
set true
. how can achieve this?
instead of trying find out if true
suggest check if none false
;)
$parts = part::wheredoesnthave('partflights', function($q){ $q->where('landed', false); })->get();
Comments
Post a Comment