Here is a crazy example today, how to use find_in_set() mysql function in laravel query builder. If you need to add tags or something that store as comma separated values in database column, then you can simply store but if also need to search then it can be hard.
Like if you have posts table with tags column you simply store data like "laravel,php,html" etc comma separated string then how you found records only tags belong to laravel. So at that moment we can use mysql find_in_set() and we can use this function using whereRaw() of laravel query builder. So let's bellow bellow syntax and example.
Syntax:
FIND_IN_SET(needle,haystack);
Example:
$data = \DB::table("posts")
->select("posts")
->whereRaw("find_in_set('laravel',tags)")
->get();
I hope you found your best.....
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example