Today, in this post i will show you how to search comma separated values in laravel. Here, we will find specific id from comma separated value and will get comma separated values from the table.
Here, we will search comma separated values using FIND_IN_SET() function. FIND_IN_SET() is predefine function of php mysql, here, we will use FIND_IN_SET() with whereRow() of laravel query builder for laravel comma separated search example. So let's see how to search comma separated values in laravel.
First of al we need to create 2 tables for find specific id from comma separated value. I have posts and tags tables in my website.
1) In posts table we have "ID", "name", "tag_id"
2) In tags table we have "ID", "name"
Here, we will find records that have ID "1" from "tag_id" column of posts table.
$search_id = 1; $data = \DB::table("posts") ->select("posts.*") ->whereRaw("find_in_set('".$search_id."',posts.tag_id)") ->get();
And you will get output like below.
You might also like :