How to Search Comma Separated Values in Laravel

$search_id = 1;
$data = \DB::table("posts")
->select("posts.*")
->whereRaw("find_in_set('".$search_id."',posts.tag_id)")
->get();
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[id] => 1
[name] => post1
[tag_id] => 1,2
)
[1] => stdClass Object
(
[id] => 2
[name] => post2
[tag_id] => 1
)
)
)

--

--

--

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Working with Lambdas in Java

How to Build Trust Using Your SMB’s Technology

title-pick

Get to Know Agile Development

Array vs List —  Compare Array and List performance in C#

How I made Redis work on Windows?

Kick imposter syndrome in the butt

Summary of Clean Code by Robert C. Martin

Review from a dev conference: Big Data, Machine learning, Ios/Android , Elastic & Chatbots

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
Websolutionstuff

Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.

More from Medium

How to create a model in Laravel

Laravel 8 Datatables Keeping Selected Page Number

Laravel Passport API that authenticates email or phone number & password

Laravel Backend — Handling Double Post Requests on SPAs caused by Browser Retries of an HTTP…