Find_in_set in Laravel (search comma-separated value from table column)

find_in_set_in_laravel

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.

find_in_set
table having comma separated value in column

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.

0 0 vote
Article Rating

Do you want to hire us for your Project Work? Then Contact US.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x