<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ahmed sabry mahfouz</title>
    <description>The latest articles on DEV Community by ahmed sabry mahfouz (@ahmedsabry1996).</description>
    <link>https://dev.to/ahmedsabry1996</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F187905%2F1b8ffe30-15d5-4ad2-8d56-a0dc974d0371.jpeg</url>
      <title>DEV Community: ahmed sabry mahfouz</title>
      <link>https://dev.to/ahmedsabry1996</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmedsabry1996"/>
    <language>en</language>
    <item>
      <title>Laravel: whereIn() vs whereIntegerInRaw() vs find()</title>
      <dc:creator>ahmed sabry mahfouz</dc:creator>
      <pubDate>Fri, 16 Feb 2024 22:39:27 +0000</pubDate>
      <link>https://dev.to/ahmedsabry1996/laravel-wherein-vs-whereintegerinraw-vs-find-2c7g</link>
      <guid>https://dev.to/ahmedsabry1996/laravel-wherein-vs-whereintegerinraw-vs-find-2c7g</guid>
      <description>&lt;p&gt;Salam Alikom guys&lt;br&gt;
if you use &lt;code&gt;whereIn()&lt;/code&gt; for a query on integer values like this:&lt;br&gt;
&lt;code&gt;Post::whereIn('id',[1,2,3])-&amp;gt;get()&lt;/code&gt; then there are other good choices to do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;the &lt;code&gt;find()&lt;/code&gt; method yes it accepts array of ids also &lt;code&gt;Post::find([1,2,3])&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the &lt;code&gt;whereIntegerInRaw()&lt;/code&gt; method like this:&lt;br&gt;
&lt;code&gt;Post::whereIntegerInRaw('id',[1,2,3])-&amp;gt;get()&lt;/code&gt; also there is another version like &lt;code&gt;whereNotIn&lt;/code&gt; which is &lt;code&gt;whereIntegerNotInRaw()&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here are the performance results of using these methods to get data in &lt;code&gt;id&lt;/code&gt; using &lt;strong&gt;10000&lt;/strong&gt; ids :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;find(rang(1,10000))&lt;/code&gt; : 30 ms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;whereIntegerInRaw('id',range(1,10000))&lt;/code&gt;: 34 ms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;whereIn('id', range(1,10000))&lt;/code&gt; : 500 ms&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it! &lt;br&gt;
Thank you :)&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>sql</category>
      <category>performance</category>
      <category>eloquentorm</category>
    </item>
  </channel>
</rss>
