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 ?
- Laravel - chmod(storage/oauth-private.key): Operation failed: Operation not permitted
- Laravel 7.x and 6.x datatables example from scratch
- How to compress PNG image using pngquant in PHP?
- Laravel 7.x and 6.x Chart example using Charts Package
- Guzzle http client GET and POST request example in Laravel 5
- Laravel schema default current timestamp value example
- Laravel 7.x and 6.x Get Site URL Examples
- Convert object to array in laravel 7.x and 6.x example