public function findByPersistenceCode($code) { return $this->createModel()->newQuery()->whereHas('persistences', function ($q) use($code) { $q->where('code', $code); })->first(); }