Find_in_set in Laravel (search comma-separated value from table column)
In this article, we will learn about how we can find search for comman separated value using find_in_set using laravel eloquent.sometimes we save our data in comma seperated pattern and we will try to get that data using where and we are unable to get that, to search in comma separted column we have to use find_in_set.
You will know more about find_in_set from here.
Below is the syntax of find_in_set
FIND_IN_SET(needle,haystack);
Now you can see the below image, which had data with comma-separated, let’s see how we can get data from that table.
Read Also: Multiple Image Upload In Laravel 8
Now we are going to use the below code to get all the data using Laravel Eloquent.
$class = '8a';
teacherMeetingDetails::whereRaw('find_in_set("'.$class.'",class)')->get();
This will return all data, where your comma separted value is matched.here teacherMeetingDetails is model of teacheMeetingDetails table.