1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

eloquent searching laravel

Discussão em 'Outras Linguagens' iniciado por Putra Edi Sujito, Outubro 3, 2024 às 13:52.

  1. I created a search feature in the disposition table. The initial display is in accordance with the eloquent that I set. but when I change the value of search , the where clause that I set cannot work as I want

    public static function search($search,$tahunId)
    {
    return empty($search) ? static::query()->with('kegiatan','opd','tahun')
    ->whereIn('tahun_id', $tahunId)
    : static::query()->with('kegiatan','opd','tahun')
    ->whereIn('tahun_id', $tahunId)
    ->where('no_proposal', 'like', '%'.$search.'%')
    ->orWhere('uraian', 'like', '%'.$search.'%')
    ->orWhere('tgl_disposisi', 'like', '%'.$search.'%')
    ->orWhere('nominal_disposisi', 'like', '%'.$search.'%')
    ->orWhere('penerima', 'like', '%'.$search.'%')
    ->orWhere('alamat', 'like', '%'.$search.'%')
    ->orWhere('status', 'like', '%'.$search.'%')
    ->orWhereHas('kegiatan',function ($q) use ($search){
    $q->where('jenis_kegiatan', 'like', '%'.$search.'%');
    })
    ->orWhereHas('opd',function ($q) use ($search){
    $q->where('nama_opd', 'like', '%'.$search.'%');
    })
    ->orWhereHas('tahun',function ($q) use ($search){
    $q->where('tahun_anggaran', 'like', '%'.$search.'%');
    $q->orWhere('tahapan', 'like', '%'.$search.'%');
    $q->orWhere('deskripsi', 'like', '%'.$search.'%');
    });
    }


    public function render()
    {
    $tahunId = Tahun::where('tahun_anggaran',$this->jadwal->tahun_anggaran)->pluck('id')->toArray();
    $disposisis = Disposisi::search($this->search, $tahunId)
    ->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
    ->paginate($this->perPage!=0 ? $this->perPage : Disposisi::count());

    return view('livewire.disposisi.disposisi-index',[
    'disposisis' => $disposisis
    ]);
    }


    tahunId has been initialized at the beginning so other than tahunId it will not appear but when I try to search for value in uraian / tgl_disposisi , where clause in tahunId doesn't work properly

    Continue reading...

Compartilhe esta Página