melx's avatar
Level 4

Search a List of data

I want to search a list of data like : 12334 23445 87878 77878 34455 which i copied from excel and paste it on my search form, then will get that data

kindly advice me the best way and example how i can archieve this

0 likes
7 replies
melx's avatar
Level 4

@van1310 , this code it handle single input?, not many input 12334 23445 87878 77878 34455 as you can see here the data is seperated by space

melx's avatar
Level 4

thanks brother, you make my day

1 like
melx's avatar
Level 4

@van1310 this code is works but how can i add another condition to search all if the status=0

      $string = $request->UnitIdList;


        // split on 1+ whitespace & ignore empty (eg. trailing space)
        $searchValues = preg_split('/\s+/', $string, -1, PREG_SPLIT_NO_EMPTY); 

        $unitList = store::where(function ($q) use ($searchValues) {
          foreach ($searchValues as $value) {
            $q->orWhere('unit_id', 'LIKE', '%' .$value. '%');
          }
        })->get();

where i can add status=0

LTroya's avatar
LTroya
Best Answer
Level 20

You can add it before the get() like this

$unitList = store::where(function ($q) use ($searchValues) {
          foreach ($searchValues as $value) {
            $q->orWhere('unit_id', 'LIKE', '%' .$value. '%');
          }
        })->where('status', 0)->get();

Please or to participate in this conversation.