Home > Enterprise >  Eager Loading With Where Condition faulty
Eager Loading With Where Condition faulty

Time:10-29

public function getListStaff(string $searchString = '')
{
    return Staff::with(['citizen_identification' => function ($query) {
        $query->where('full_name', 'like', '%' . $searchString . '%');
    }])
        ->where('phone', 'like', '%' . $searchString . '%')
        ->orWhere('email', 'like', '%' . $searchString . '%')
        ->paginate(2);
}

enter image description here

I use Repository in project livewire of me, i newbie use livewire, when i code method getListStaff is faulty, i try fix, but not success, please help me fix... Thanhks bros

Because I wrong syntax or visual code error or so ???

CodePudding user response:

It seems like you have missed use statement for searchstring.

In any case, based from you question its not clear what is not working.


        return Staff::with([
            'citizen_identification' => function ($query) use ($searchString) {
                $query->where('full_name', 'like', '%'.$searchString.'%');
            },
        ])
            ->where('phone', 'like', '%'.$searchString.'%')
            ->orWhere('email', 'like', '%'.$searchString.'%')
            ->paginate(2);
  • Related