How do I add the following filter when searching through the datatable?

How do I add the following filter when searching through the datatable?

thatdudermthatduderm Posts: 2Questions: 2Answers: 0
edited September 2021 in DataTables
if ($request->first_name) {
            $qb->andWhere($qb->expr()->like('`First Name`', ':first_name'))
                ->setParameter('first_name', '%' . str_replace('%', '', $request->first_name) . '%');
        }
        if ($request->middle_name) {
            $qb->andWhere($qb->expr()->like('`Middle Name`', ':middle_name'))
                ->setParameter('middle_name', '%' . str_replace('%', '', $request->middle_name) . '%');
        }
        if ($request->last_name) {
            $qb->andWhere($qb->expr()->like('`Last Name`', ':last_name'))
                ->setParameter('last_name', '%' . str_replace('%', '', $request->last_name) . '%');
        }
        if ($request->section) {
            $qb->andWhere('`Section` = :section')
                ->setParameter('section',  $request->section);
        }
        if ($request->lot_num) {
            $qb->andWhere('`Lot Number` = :lot_num')
                ->setParameter('lot_num',  $request->lot_num);
        }
        if ($request->dod) {
            $qb->andWhere('year(`Date of Death`) = :dod')
                ->setParameter('dod',  $request->dod);
        }
        if ($request->dob) {
            $qb->andWhere('year(`Date of Birth`) = :dob')
                ->setParameter('dob',  $request->dob);
        }

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    You are going to need to elaborate on your question for me. Are you looking to replicate the code you have there with our Editor PHP libraries, or something else? If you are, then:

    $editor->where(function ($q) use ($request) {
      if ($request->first_name) {
        $q-where('first_name', '%'.$request->first_name.'%', 'LIKE');
      }
      ...
    })
    

    Would do it. See the documentation here.

    Allan

Sign In or Register to comment.