{"id":1090,"date":"2024-07-26T12:44:23","date_gmt":"2024-07-26T12:44:23","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=1090"},"modified":"2025-05-15T04:59:11","modified_gmt":"2025-05-15T04:59:11","slug":"laravel-eloquent-wherein-query-example","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/laravel-eloquent-wherein-query-example\/","title":{"rendered":"Laravel Eloquent WhereIn Query Example"},"content":{"rendered":"\n<p>Hello Artisans, Today we will see wherein query in Laravel eloquent, How laravel model works with wherein array query. Here i will tell you some examples of wherein laravel query builder. also you can use laravel eloquent where is array. <\/p>\n\n\n\n<p>With these examples, you can use wherein eloquent method in all laravel versions Laravel7, laravel8, laravel9, Laravel10 and Laravel 11. <\/p>\n\n\n\n<p>If you want to use your mysql wherein query in laravel then you can use with this array. Laravel provide wherein() eloquent method to use SQL wherein query. In wherein() eloquent query, you just need to pass two arguments, where one is column name and another if array of ids or anything that you want. <\/p>\n\n\n\n<p>You can see bellow syntax on wherein query in laravel:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">whereIn(Coulumn_name, Array);<\/pre><\/div>\n\n\n\n<p>Now, we will see three examples how we will use wherein eloquent query in laravel application. So let&#8217;s see these examples, how it works:<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-54a67bb6bf8449dba147da716dff862a\">Example Number 1<\/p>\n\n\n\n<p>Our <strong>SQL Query:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;SQL&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">SELECT * FROM users WHERE id IN (4, 5, 6) <\/pre><\/div>\n\n\n\n<p><strong>Laravel Query:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">public function index()\n{\n    $users = User::select(&quot;*&quot;)\n                    -&gt;whereIn('id', [4, 5, 6])\n                    -&gt;get();\n  \n    dd($users);                    \n}<\/pre><\/div>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-239247d7cb007df86bee3bee20fb438d\"><strong>Example 2:<\/strong><\/p>\n\n\n\n<p>Here is another example of wherein query. You can work with comma separated string value. you can work as like bellow:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">public function index()\n{\n    $myString = '1,2,3';\n    $myArray = explode(',', $myString);\n    \n    $users = User::select(&quot;*&quot;)\n                    -&gt;whereIn('id', $myArray)\n                    -&gt;get();\n  \n    dd($users);                    \n}<\/pre><\/div>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-fe8b5dddf3233cdea22c1bc7648ebd15\"><strong>Example 3:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">public function index()\n{\n    $users = DB::table('users')\n                    -&gt;whereIn('name', ['Kishan', 'Soniya', 'Salmaan'])\n                    -&gt;get();\n  \n    dd($users);                    \n}<\/pre><\/div>\n\n\n\n<p>I hope this example of whereIn eloquent query builder help you to understand, how you can filter datas from a table using whereIn laravel query builder. <\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#f0f0f0\"><a href=\"https:\/\/www.appfinz.com\/blogs\/how-to-use-jquery-animation-effects\/\">How to use jQuery Animation Effects<\/a><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-background has-link-color wp-elements-822d1766891bdd6c6f85413c87dfc01a\" style=\"background-color:#e9ebed\"><a href=\"https:\/\/www.appfinz.com\/blogs\/how-to-check-if-a-key-exists-in-a-javascript-object\/\">Check If a Key Exists in a JavaScript<\/a><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-background has-link-color wp-elements-5c585f3d523c6e988e77fe4c1a4558eb\" style=\"background-color:#e9ebed\"><a href=\"https:\/\/www.appfinz.com\/blogs\/php-common-how-to-solutions\/\">PHP Common How to Solutions<\/a><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-background has-link-color wp-elements-5217f68aaa146b8d40fafd6f4a797a02\" style=\"background-color:#e9ebed\"><a href=\"https:\/\/www.appfinz.com\/blogs\/understanding-this-in-javascript\/\">Understanding \u201cthis\u201d in JavaScript<\/a><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-background has-link-color wp-elements-fd4fa2b2739c39086023e0de22979002\" style=\"background-color:#e9ebed\"><strong><a href=\"https:\/\/www.appfinz.com\/blogs\/paypal-payment-gateway-integration-in-laravel-11\/\">Paypal Payment Gateway Integration in Laravel 11<\/a><\/strong><\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#f1f5fb\">If you&#8217;re planning to build a feature-rich online platform, explore our <a href=\"https:\/\/www.appfinz.com\/web-portal-development\"><strong>web portal development<\/strong><\/a> and <a href=\"https:\/\/www.appfinz.com\/b2b-portal-development\"><strong>B2B portal solutions<\/strong><\/a> tailored for scalability and performance.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Artisans, Today we will see wherein query in Laravel eloquent, How laravel model works<\/p>\n","protected":false},"author":1,"featured_media":650,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[114,155,156,157],"class_list":["post-1090","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-laravel","tag-laravel-eloquent","tag-laravel-query-builder","tag-wherein-laravel"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/comments?post=1090"}],"version-history":[{"count":2,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1090\/revisions"}],"predecessor-version":[{"id":1362,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1090\/revisions\/1362"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media\/650"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}