Как правильно переписать eloquent запрос?

Как правильно переписать eloquent запрос? В контроллере ларавел есть такая функция:

public function indexpage($count, $id, $freePersons, $refertype, $referid)
{
    if(!$freePersons) {$arrRel = DB::table('relpeople')->pluck('person_id');} else {$arrRel = [];};
        
    if($refertype == 'none') {
        $retPersons = Person::whereNotIn('id', $arrRel)->offset($count * ($id - 1))->limit($count)->get(); 
        $retCountRecords = Person::whereNotIn('id', $arrRel)->count();
    }
    if($refertype == 'company') {
        $retPersons = Company::findOrFail($referid)->persons->whereNotIn('id', $arrRel)->offset($count * ($id - 1))->limit($count)->get();
        $retCountRecords = Company::findOrFail($referid)->persons->whereNotIn('id', $arrRel)->count();
    }
    if($refertype == 'department') {
        $retPersons = Department::findOrFail($referid)->persons->whereNotIn('id', $arrRel)->offset($count * ($id - 1))->limit($count)->get();
        $retCountRecords = Department::findOrFail($referid)->persons->whereNotIn('id', $arrRel)->count();
    }
    
    forEach($retPersons as $person) {
        $person->equipments;
        $person->acts;
    };
    
    $retData = response()->json(['persons' => $retPersons, 'countrecords' => $retCountRecords]);
    return $retData;        
}

рнр ругается на offset после wherenotin во втором и третьем if - нет такого метода. Суть в том что найти людей в подразделениях или в головном офисе или вообще всех зарегистрированных людей и вывести с пагинацией во vue. Помогите переписать запрос в eloquent. Первый if работает так как надо. FreePersons нужен чтобы найти людей не относящихся к какой либо фирме или подразделению


Ответы (0 шт):