How To Search Comma Separated Values In Laravel

In this article, we will see how to search comma separated values in laravel. Here, we will find specific id from comma separated values 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 a predefined function of PHP MySQL. Also, we will use FIND_IN_SET() with whereRow() of the laravel query builder for the laravel comma separated search example.

So, let’s see how to find comma separated values in laravel 8, and get comma separated values in laravel.

First of all, we need to create 2 tables to find specific id from comma separated values. I have posts and tags tables on my website.

1. In the posts table we have “ID”, “name”, “tag_id”.

2. In the tags table we have “ID”, “name”.

Here, we will find records that have ID “1” from the “tag_id” column of the posts table.

And you will get output like the below.

[1] => stdClass Object
(
[id] => 2
[name] => post2
[tag_id] => 1
)
)
)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Techsolutionstuff

The Techsolutionstuff is to help for beginner programmers who want to start career in web development or learn web development technologies or languages.