I have numbers stored as comma separated in the database field e.g ticketNumbers:1,2,3,12,45,67. The user has a textbox in laravel blade where he/she enters the 6 numbers to search people with those numbers. Now in my blade l want to only retrieve people that have more than 4 numbers that are similar to the searched numbers. Below is the function in my controller to search but its showing everyone even with one number matched.
public function findPerson(Request $request)
{
$s = $request->search;
$s1 = $request->search1;
$s2 = $request->search2;
$s3 = $request->search3;
$s4 = $request->search4;
$s5 = $request->search5;
$fac = $s.','.$s1.','.$s2.','.$s3.','.$s4.','.$s5;
$data = explode(',',$fac);
$str='';
$i=1; // to append AND in query
foreach ($data as $key => $value) {
$str .= 'FIND_IN_SET("'.$value.'" ,ticketNumbers)';
if($i < count($data)){
$str .=' OR '; // use OR as per use
}
$i++;
}
$raffles = Raffle::whereRaw($str)->get();
return View('raffles.index', compact('raffles'));
}
Below is the screenshot of my blade view