<?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: ByteBricks.ai</title>
    <description>The latest articles on DEV Community by ByteBricks.ai (@bytebricks).</description>
    <link>https://dev.to/bytebricks</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%2F1169154%2F121dce28-42c3-46ab-b94e-2d143b920a07.png</url>
      <title>DEV Community: ByteBricks.ai</title>
      <link>https://dev.to/bytebricks</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bytebricks"/>
    <language>en</language>
    <item>
      <title>Unleashing Laravel Queues with AWS SQS: A Step Towards Outsourced Processing</title>
      <dc:creator>ByteBricks.ai</dc:creator>
      <pubDate>Wed, 11 Oct 2023 18:59:34 +0000</pubDate>
      <link>https://dev.to/bytebricks/unleashing-laravel-queues-with-aws-sqs-a-step-towards-outsourced-processing-2ko</link>
      <guid>https://dev.to/bytebricks/unleashing-laravel-queues-with-aws-sqs-a-step-towards-outsourced-processing-2ko</guid>
      <description>&lt;p&gt;In the ever-evolving landscape of web development, the ability to offload and manage tasks asynchronously is no longer a luxury, but a necessity. Especially when dealing with resource-hungry 🤑operations that could potentially bring your application to a crawl. &lt;/p&gt;

&lt;p&gt;This is where &lt;a href="https://laravel.com/"&gt;Laravel&lt;/a&gt;’s queue management shines, and coupling it with Amazon Simple Queue Service (AWS &lt;a href="https://aws.amazon.com/sqs/"&gt;SQS&lt;/a&gt;) is like giving it a jetpack to soar into the clouds. This duo allows you to dispatch jobs to be handled by external &lt;a href="https://laravel.com/docs/10.x/queues"&gt;workers&lt;/a&gt;, thereby outsourcing resources and ensuring your application runs smoothly, no matter the load.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting The Stage
&lt;/h2&gt;

&lt;p&gt;Before we dive into the mechanics, ensure you have the &lt;a href="https://aws.amazon.com/sdk-for-php/"&gt;AWS SDK&lt;/a&gt; for PHP installed via &lt;a href="https://getcomposer.org/"&gt;Composer&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require aws/aws-sdk-php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring Laravel
&lt;/h2&gt;

&lt;p&gt;In your Laravel project, navigate to &lt;code&gt;config/queue.php&lt;/code&gt; and configure the &lt;strong&gt;sqs&lt;/strong&gt; connection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'sqs'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'driver'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sqs'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'key'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'AWS_ACCESS_KEY_ID'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="s1"&gt;'secret'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'AWS_SECRET_ACCESS_KEY'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="s1"&gt;'prefix'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'AWS_SQS_PREFIX'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'https://sqs.us-east-1.amazonaws.com/your-account-id'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="s1"&gt;'queue'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'AWS_SQS_QUEUE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'your-queue-name'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="s1"&gt;'region'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'AWS_DEFAULT_REGION'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'us-east-1'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your &lt;code&gt;.env&lt;/code&gt; file, make sure to fill in the necessary AWS credentials and queue information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-access-key-id
&lt;span class="nv"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-secret-access-key
&lt;span class="nv"&gt;AWS_SQS_PREFIX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://sqs.us-east-1.amazonaws.com/your-account-id
&lt;span class="nv"&gt;AWS_SQS_QUEUE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-queue-name
&lt;span class="nv"&gt;AWS_DEFAULT_REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prepping Your Jobs
&lt;/h2&gt;

&lt;p&gt;Creating a job in Laravel is a breeze. Use the *&lt;em&gt;Artisan *&lt;/em&gt; 😍command to generate a new &lt;a href="https://laravel.com/docs/10.x/queues"&gt;job class&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:job ProcessTask
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a &lt;code&gt;ProcessTask&lt;/code&gt; class within the &lt;code&gt;App\Jobs&lt;/code&gt; namespace. Here’s a _simplified _ example of what your job might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Jobs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Bus\Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Contracts\Queue\ShouldQueue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Foundation\Bus\Dispatchable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Queue\InteractsWithQueue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Queue\SerializesModels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProcessTask&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;ShouldQueue&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Dispatchable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;InteractsWithQueue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Queueable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SerializesModels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Process your data...&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dispatching Jobs to AWS SQS
&lt;/h2&gt;

&lt;p&gt;Dispatching a job to the SQS queue is as simple as calling the dispatch method on your job class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;ProcessTask&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your job is now on a swift journey to &lt;strong&gt;AWS SQS&lt;/strong&gt; 🎉, awaiting an external worker to pick it up 😋.&lt;/p&gt;

&lt;h2&gt;
  
  
  External Workers: The Unsung Heroes 👑
&lt;/h2&gt;

&lt;p&gt;Having your jobs dispatched is half the battle. Now comes the part where external workers step in to process these jobs. You could set up a dedicated server or utilize a service that specializes in processing queue jobs.&lt;/p&gt;

&lt;p&gt;On your worker server, ensure you have a &lt;strong&gt;clone of your Laravel project&lt;/strong&gt;. Then, run the queue worker to start processing jobs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan queue:work sqs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scaling the Horizon
&lt;/h2&gt;

&lt;p&gt;By now, you have a well-oiled machine ready to handle a barrage of tasks without breaking a sweat. This setup shines in scenarios where resource-intensive tasks can be outsourced to external workers, allowing your main application to serve user requests swiftly.&lt;/p&gt;

&lt;p&gt;Moreover, this model is scalable. As the load increases, spawn more workers to chew through the job queue😄. It’s all about keeping the gears turning smoothly while your &lt;a href="https://dev.to/bytebricks/explain-api-like-im-five-23eb"&gt;application&lt;/a&gt; continues to cater to your users without a hiccup.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Bite of Real-world Scenario
&lt;/h2&gt;

&lt;p&gt;Imagine a case where your application needs to scrape vast amounts of data from various sources. The &lt;a href="https://dev.to/bytebricks/cheerio-chatgpt-a-primer-on-web-scraping-with-nodejs-4klf"&gt;web scraping&lt;/a&gt; tasks are perfect candidates for outsourcing. Dispatch these tasks to AWS SQS, let the external workers do the heavy lifting, and have the results shipped back to your application for further use.&lt;/p&gt;

&lt;p&gt;With a friendly &lt;strong&gt;handshake&lt;/strong&gt; between Laravel and AWS SQS, the sky's the limit in managing asynchronous tasks efficiently. This setup not only paves the way for &lt;a href="https://dev.to/bytebricks/unleashing-the-power-of-wherehas-in-laravel-jip"&gt;better resource management&lt;/a&gt; but also sets a robust foundation for scaling your application as it grows. It’s about making your application a well-coordinated orchestra, delivering a seamless symphony of operations, with each musician, the external worker in this case, playing its part to perfection.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>microservices</category>
      <category>tutorial</category>
      <category>devops</category>
    </item>
    <item>
      <title>I hate Typescript, is it a shame?</title>
      <dc:creator>ByteBricks.ai</dc:creator>
      <pubDate>Wed, 04 Oct 2023 20:28:21 +0000</pubDate>
      <link>https://dev.to/bytebricks/i-hate-typescript-is-it-shame-5cek</link>
      <guid>https://dev.to/bytebricks/i-hate-typescript-is-it-shame-5cek</guid>
      <description>&lt;p&gt;But am I alone in this boat, gently rowing down the river of resistance against the *&lt;em&gt;TypeScript *&lt;/em&gt; tide? Or are there others who share this sentiment 😍? Or better yet, are there knights in shining armor ready to defend TypeScript’s honor and educate the peasants like me on the path of righteous coding 🤣🤣?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I love Javascript but Hate Typescript!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Here are some discussion nuggets to chew on:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Why is TypeScript hailed as the savior of big projects? Is it really the unsung hero in the sprawling chaos of JavaScript?&lt;/li&gt;
&lt;li&gt;For the TypeScript fans, share your “Aha!” moment when TypeScript clicked for you 😎.&lt;/li&gt;
&lt;li&gt;And for my fellow “TypeScript skeptics”, why do you really hate it?&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>react</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Explain API Like I'm Five</title>
      <dc:creator>ByteBricks.ai</dc:creator>
      <pubDate>Tue, 03 Oct 2023 23:06:05 +0000</pubDate>
      <link>https://dev.to/bytebricks/explain-api-like-im-five-23eb</link>
      <guid>https://dev.to/bytebricks/explain-api-like-im-five-23eb</guid>
      <description>&lt;p&gt;&lt;a href="https://bytebricks.ai/"&gt;We&lt;/a&gt; build and sell &lt;strong&gt;Data API&lt;/strong&gt;s, I want the help of this great community on explaining API service to non developers, business people, and users. How will you explain it?&lt;/p&gt;

</description>
      <category>explainlikeimfive</category>
      <category>javascript</category>
      <category>laravel</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Laravel: Tailwind Livewire UI Components</title>
      <dc:creator>ByteBricks.ai</dc:creator>
      <pubDate>Tue, 03 Oct 2023 22:37:14 +0000</pubDate>
      <link>https://dev.to/bytebricks/laravel-tailwind-livewire-ui-components-8pn</link>
      <guid>https://dev.to/bytebricks/laravel-tailwind-livewire-ui-components-8pn</guid>
      <description>&lt;p&gt;Oh, the sweet allure of &lt;a href="https://tailwindcss.com/"&gt;Tailwind CSS&lt;/a&gt;! It’s like that trendy cafe downtown everyone wants a piece of. The sleek, utility-first structure it brings to the table has made it a darling in the web development realm. Now, pair that up with &lt;a href="https://laravel.com/"&gt;Laravel&lt;/a&gt; &lt;a href="https://laravel-livewire.com/"&gt;Livewire&lt;/a&gt;, and you’ve got yourself a match made in heaven, or should I say, in code. But what if we could spice this love affair up a notch? Enter WireUI components at &lt;a href="https://livewire-wireui.com/"&gt;Livewire-WireUI.com&lt;/a&gt;. This nifty toolkit is like the secret sauce to injecting Tailwind CSS goodness into &lt;strong&gt;Livewire&lt;/strong&gt;, making &lt;strong&gt;Laravel&lt;/strong&gt; development faster, more enjoyable, and oh-so beautiful 😍.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cutting to the Chase with WireUI
&lt;/h2&gt;

&lt;p&gt;We’ve all been there - wanting to whip up a user interface that’s not only easy on the eyes but also a breeze to work with. That's where WireUI comes in, offering a smorgasbord of pre-built UI components 🔥 ready to be embraced by your Livewire projects. It’s like finding a shortcut on your morning commute that shaves off precious minutes, allowing you to catch extra zzz’s or, let’s be honest, another episode of your favorite series😎.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind CSS Meets Livewire: A Symphony of Productivity
&lt;/h2&gt;

&lt;p&gt;The harmony between &lt;strong&gt;Tailwind CSS&lt;/strong&gt; and &lt;strong&gt;Livewire&lt;/strong&gt; is something akin to a well-orchestrated symphony. Tailwind CSS lays down the rhythm with its intuitive utility classes, making styling feel like a walk in the park. On the other hand, Livewire conducts the melody, orchestrating state-driven components seamlessly without breaking a sweat😁.&lt;/p&gt;

&lt;h2&gt;
  
  
  Look at these nice components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Simple Input&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I_dHsZSf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ftdpd6s31r7jbb1r9iow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I_dHsZSf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ftdpd6s31r7jbb1r9iow.png" alt="livewire tailwind Simple Input" width="531" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Email input with suffix&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kq_wqa1x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7ex48evsc5oacmftavg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kq_wqa1x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7ex48evsc5oacmftavg.png" alt="livewire tailwind Email input with suffix" width="512" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Searchable Select Dropdown!&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CSVTySVl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sliaqi3akkaglys5hmou.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CSVTySVl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sliaqi3akkaglys5hmou.png" alt="livewire tailwind Searchable Select Dropdown!" width="448" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Color Picker&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_sPM0WcI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7k0o1q7523gqbo62gaol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_sPM0WcI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7k0o1q7523gqbo62gaol.png" alt="livewire tailwind Color Picker" width="432" height="381"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Diving Deeper: A Look Under the Hood
&lt;/h2&gt;

&lt;p&gt;To install simply&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require wireui/wireui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the WireUI tag above Alpinejs script tag in your page layout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        ...
        &lt;span class="nt"&gt;&amp;lt;wireui:scripts&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"//unpkg.com/alpinejs"&lt;/span&gt; &lt;span class="na"&gt;defer&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can use the equivalent Blade directive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;...
@wireUiScripts
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"//unpkg.com/alpinejs"&lt;/span&gt; &lt;span class="na"&gt;defer&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
...

Sometimes you need to pass extra html attributes to script tag, like the nonce attribute
@wireUiScripts(['nonce': 'csp-token'])
@wireUiScripts(['nonce': 'csp-token', 'foo' =&amp;gt; true])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following settings to your Tailwindcss config file, tailwind.config.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="na"&gt;presets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;
        &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./vendor/wireui/wireui/tailwind.config.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./vendor/wireui/wireui/resources/**/*.blade.php&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./vendor/wireui/wireui/ts/**/*.ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./vendor/wireui/wireui/src/View/**/*.php&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WireUI does not need any additional configuration, but you can publish the files and customize them to your preference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan vendor:publish --tag='wireui.config'
php artisan vendor:publish --tag='wireui.resources'
php artisan vendor:publish --tag='wireui.lang'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Beyond the Horizon: Exploring the Ecosystem
&lt;/h2&gt;

&lt;p&gt;The beauty of the Laravel ecosystem is its boundless capacity for growth and innovation. Take &lt;a href="https://bytebricks.ai/"&gt;ByteBricks&lt;/a&gt; for instance. This platform takes Laravel development up a notch, offering solutions that dovetail perfectly with the principles of rapid, elegant coding we see in WireUI.&lt;/p&gt;

&lt;p&gt;Remember our little rendezvous with &lt;a href="https://dev.to/bytebricks/unleashing-the-power-of-wherehas-in-laravel-jip"&gt;Laravel’s whereHas&lt;/a&gt; magic? Or that time we embarked on a data-scraping quest with &lt;a href="https://dev.to/bytebricks/cheerio-chatgpt-a-primer-on-web-scraping-with-nodejs-4klf"&gt;GPT-3 and Cheerio&lt;/a&gt;? Well, WireUI fits right into this narrative of efficiency and elegance. It’s about having the right tools at your disposal to transform ideas into reality, without getting entangled in the nitty-gritty. With the Laravel ecosystem continually evolving, who knows what exciting concoctions we’ll stir up next?&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>tailwindcss</category>
      <category>javascript</category>
      <category>livewire</category>
    </item>
    <item>
      <title>Cheerio &amp; ChatGPT: A Primer on Web Scraping with Node.js</title>
      <dc:creator>ByteBricks.ai</dc:creator>
      <pubDate>Sat, 30 Sep 2023 21:27:04 +0000</pubDate>
      <link>https://dev.to/bytebricks/cheerio-chatgpt-a-primer-on-web-scraping-with-nodejs-4klf</link>
      <guid>https://dev.to/bytebricks/cheerio-chatgpt-a-primer-on-web-scraping-with-nodejs-4klf</guid>
      <description>&lt;p&gt;Hey there fellow data digger (we dig at &lt;a href="https://bytebricks.ai/"&gt;bytebricks.ai&lt;/a&gt;)! The web is a treasure trove of information waiting to be unearthed. And guess what? With a sprinkle of &lt;a href="https://cheerio.js.org/"&gt;Cheerio&lt;/a&gt; and a dash of &lt;a href="https://nodejs.org/en"&gt;Node.js&lt;/a&gt;, you can turn your code into a data-gathering wizard.&lt;/p&gt;

&lt;p&gt;But, hey, let's add a fun twist to it! Ever heard of &lt;a href="https://chat.openai.com/"&gt;ChatGPT&lt;/a&gt;? 😂 This buddy can take a peek at HTML and whip up the Cheerio code you need to grab that data. Let’s dive into this delicious bowl of Cheerio (pun totally intended) and see how we can make web scraping a breeze.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepping Up
&lt;/h2&gt;

&lt;p&gt;Before we start, make sure Node.js is comfortably nestled in your machine. Create a cozy little space for your project, hop into that directory via the terminal, and kickstart a new Node.js project with a simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next up, let’s invite Cheerio and &lt;a href="https://github.com/axios/axios"&gt;Axios&lt;/a&gt; (our trusty HTTP client) to the party with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install cheerio axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Snagging that HTML
&lt;/h2&gt;

&lt;p&gt;Alright, with the gang all set, let’s nab the HTML of the website we’re eyeing. For this little adventure, we’re gonna pretend we’re extracting goodies from a make-believe e-commerce site.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const axios = require('axios');

async function fetchHTML(url) {
  const { data } = await axios.get(url);
  return data;
}

const url = 'https://fictional-ecommerce-site.com';
fetchHTML(url).then(console.log);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let Cheerio Lead the Way
&lt;/h2&gt;

&lt;p&gt;Got the HTML? Sweet! Now, let’s hand it over to Cheerio for some parsing action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cheerio = require('cheerio');

async function parseHTML(html) {
  const $ = cheerio.load(html);

  // Let’s pretend each product is nestled
  $('.product').each((i, element) =&amp;gt; {
    const title = $(element).find('.product-title').text();
    const price = $(element).find('.product-price').text();

    console.log(`${title}: ${price}`);
  });
}

fetchHTML(url).then(html =&amp;gt; parseHTML(html));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See what we did there? It’s like we’re using &lt;strong&gt;jQuery!&lt;/strong&gt;, but with the turbo engines of Node.js.&lt;/p&gt;

&lt;h2&gt;
  
  
  ChatGPT comes handy
&lt;/h2&gt;

&lt;p&gt;Now for the cherry on top! ChatGPT can take a look at HTML and conjure up the Cheerio code you need to snatch that data. Just feed it the HTML, and voila, you’ve got your data extraction code ready to roll. It's like having a buddy who writes code while you munch on snacks!&lt;/p&gt;

&lt;h2&gt;
  
  
  Polishing Your Data Scooper
&lt;/h2&gt;

&lt;p&gt;Crafting a web scraper is kinda like brewing the perfect cup of coffee. It needs a little tinkering to hit that sweet spot between speed and accuracy. With Cheerio, Node.js, and a little help from ChatGPT, you’ve got a solid start. Don’t forget to handle those pesky paginations, asynchronous loads, and rate limits to scrape like a pro!😎&lt;/p&gt;

&lt;h2&gt;
  
  
  Further
&lt;/h2&gt;

&lt;p&gt;You need to make data useful! at bytebricks we build using a Laravel backend and a Vue front, we find that fast to market and Laravel using SQL have a low ongoing overhead cost! not to mention the magic of &lt;a href="https://laravel.com/docs/10.x/eloquent"&gt;Eloquent&lt;/a&gt; as in this example of &lt;a href="https://dev.to/bytebricks/unleashing-the-power-of-wherehas-in-laravel-jip"&gt;whereHas&lt;/a&gt; or the very easy integration of &lt;a href="https://dev.to/bytebricks/integrating-aws-simple-email-service-ses-with-laravel-a-comprehensive-guide-1lj3"&gt;AWS SES&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>node</category>
      <category>ai</category>
    </item>
    <item>
      <title>Integrating AWS Simple Email Service (SES) with Laravel: A Comprehensive Guide</title>
      <dc:creator>ByteBricks.ai</dc:creator>
      <pubDate>Tue, 26 Sep 2023 19:25:47 +0000</pubDate>
      <link>https://dev.to/bytebricks/integrating-aws-simple-email-service-ses-with-laravel-a-comprehensive-guide-1lj3</link>
      <guid>https://dev.to/bytebricks/integrating-aws-simple-email-service-ses-with-laravel-a-comprehensive-guide-1lj3</guid>
      <description>&lt;p&gt;&lt;a href="https://aws.amazon.com/"&gt;AWS&lt;/a&gt; Simple Email Service (&lt;a href="https://aws.amazon.com/ses/"&gt;SES&lt;/a&gt;) has carved a niche for itself as a potent solution for delivering transactional emails, promotional content, and we use that service as a primary provider on &lt;a href="https://bytebricks.ai/"&gt;bytebricks.ai&lt;/a&gt; delivering our emails and customers emails as well. &lt;/p&gt;

&lt;p&gt;Marrying AWS SES with &lt;a href="https://laravel.com/"&gt;Laravel&lt;/a&gt; (&lt;a href="https://dev.to/bytebricks/unleashing-the-power-of-wherehas-in-laravel-jip"&gt;we are big fans&lt;/a&gt;) opens the doors to efficient email management, high deliverability rates, and cost-effective solutions.&lt;/p&gt;

&lt;p&gt;This article is a dive into how to seamlessly integrate AWS SES with a Laravel application, the advantages of this integration, and hands-on steps with relevant code blocks. As an icing on the cake, our subsequent article will explore the nuances of AWS Simple Notification Service (&lt;a href="https://aws.amazon.com/sns/"&gt;SNS&lt;/a&gt;). Let’s embark on this journey!&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Using AWS SES in Laravel Applications:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cost-Effective Solution:&lt;/strong&gt; Unlike traditional systems that come with hidden fees or fixed monthly costs, SES operates on a pay-as-you-go model. This is especially beneficial for startups and mid-sized businesses that are budget-conscious.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Incredible Scalability:&lt;/strong&gt; Leveraging Amazon's renowned infrastructure, SES promises high deliverability rates, even when you're sending out a massive volume of emails. This scalability ensures that as your business grows, your email solution grows with you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unwavering Reliability:&lt;/strong&gt; Built on the bedrock of Amazon's robust infrastructure, SES ensures that your emails don’t just end up in the abyss but reach your intended recipients.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Seamless Integration:&lt;/strong&gt; SES can be effortlessly coupled with other AWS services. Imagine integrating SES with SNS for real-time notifications or AWS Lambda for serverless code execution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stringent Security Measures:&lt;/strong&gt; AWS leaves no stone unturned in ensuring your emails are encrypted end-to-end. This guarantees that your sensitive emails are shielded from prying eyes during transit.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Hands-on Integration of AWS SES with Laravel:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Setting Up AWS SES:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Manage Your AWS Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To kickstart your journey, sign into the AWS Management Console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verify an Email Address:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before you venture into sending emails, AWS mandates the verification of your email address with SES. This is a security measure to confirm that you have rightful access to the sender's email address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initiate Email Sending:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With your email now verified, the gates are open to send emails. SES offers three avenues: the console, SMTP interface, or the API. For Laravel aficionados, the API is your best bet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Integrate SES with Laravel:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Installation: The first step is to bring the AWS SDK for PHP onboard. This can be achieved with composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require aws/aws-sdk-php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the SDK in place, the next step is to etch your AWS credentials in the .env file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_DEFAULT_REGION=your_region
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Laravel Mail Configuration:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Modify the &lt;code&gt;mail.php&lt;/code&gt; configuration file to employ SES as your mail driver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'mail' =&amp;gt; [
    'driver' =&amp;gt; 'ses',
    'key' =&amp;gt; env('AWS_ACCESS_KEY_ID'),
    'secret' =&amp;gt; env('AWS_SECRET_ACCESS_KEY'),
    'region' =&amp;gt; env('AWS_DEFAULT_REGION')
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Crafting and Sending Emails:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Laravel’s innate Mail facade is your trusted ally in sending emails. With SES as the driver, the process remains seamless.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Support\Facades\Mail;

Mail::send('emails.test', ['user' =&amp;gt; $user], function ($m) use ($user) {
    $m-&amp;gt;to($user-&amp;gt;email, $user-&amp;gt;name)-&amp;gt;subject('AWS SES Test!');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Monitoring Your Emails:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AWS SES isn’t just about sending emails. It’s also about ensuring they reach the promised land. SES provides tools to monitor metrics like delivery rates, bounce rates, and complaints.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$metrics = SES::getMetrics();
echo $metrics['DeliveryRate'];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Handling Bounces &amp;amp; Complaints:&lt;/strong&gt;&lt;br&gt;
Here’s where the magic of AWS SNS will come into play. SNS ensures you're instantly notified about pivotal email events such as bounces or complaints. However, the nitty-gritty of AWS SNS will be the highlight of our next article.&lt;/p&gt;

&lt;p&gt;In Conclusion:&lt;/p&gt;

&lt;p&gt;The synergy between AWS SES and Laravel promises an unparalleled email experience. With SES’s cost efficiency, scalability, and reliability coupled with Laravel’s simplicity, developers can effortlessly send, manage, and monitor emails.&lt;/p&gt;

&lt;p&gt;Happy coding, and see you in the world of AWS SNS notifications! 🚀👨‍💻&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>aws</category>
      <category>ses</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Unleashing the Power of whereHas in Laravel</title>
      <dc:creator>ByteBricks.ai</dc:creator>
      <pubDate>Mon, 25 Sep 2023 01:06:36 +0000</pubDate>
      <link>https://dev.to/bytebricks/unleashing-the-power-of-wherehas-in-laravel-jip</link>
      <guid>https://dev.to/bytebricks/unleashing-the-power-of-wherehas-in-laravel-jip</guid>
      <description>&lt;p&gt;Hello, wonderful dev.to community! As a &lt;a href="https://twitter.com/MaenHouseh"&gt;senior developer&lt;/a&gt; who's been working with &lt;a href="https://laravel.com/"&gt;Laravel&lt;/a&gt; for quite some time, I've come to appreciate the nuances and powerful features it offers. Today, I want to talk about a hidden gem: the &lt;strong&gt;whereHas&lt;/strong&gt; method. This method provides a clean, elegant way to filter results based on relationship constraints.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is whereHas?
&lt;/h2&gt;

&lt;p&gt;In Laravel, &lt;a href="https://laravel.com/docs/10.x/eloquent-relationships"&gt;relationships&lt;/a&gt; are a cornerstone of Eloquent ORM. However, sometimes we need to filter the results of our primary model based on the presence or properties of a related model.&lt;/p&gt;

&lt;p&gt;In a nutshell, whereHas lets you apply conditions to your Eloquent queries based on related model data, we used that over and over building our API at &lt;a href="https://bytebricks.ai/"&gt;Bytebricks.ai&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Example
&lt;/h2&gt;

&lt;p&gt;Imagine we have a Post model and each Post can have many Comment models. Now, let's say we want to fetch all posts that have at least one comment. With whereHas, this is a breeze:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$postsWithComments = Post::whereHas('comments')-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Diving Deeper
&lt;/h2&gt;

&lt;p&gt;What if we want to fetch posts with comments from a specific user? With whereHas, you can provide a closure to add additional constraints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$userId = 1;
$postsWithCommentsFromUser = Post::whereHas('comments', function ($query) use ($userId) {
    $query-&amp;gt;where('user_id', $userId);
})-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Counting Related Models
&lt;/h2&gt;

&lt;p&gt;whereHas can also be used with the withCount method to get the number of related models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$posts = Post::withCount('comments')-&amp;gt;get();

foreach ($posts as $post) {
    echo $post-&amp;gt;comments_count;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Performance Tips
&lt;/h2&gt;

&lt;p&gt;While whereHas is powerful, be mindful of the N+1 problem. Ensure you're using methods like with() to eager-load relationships when needed. The Laravel Debugbar is a great tool for keeping an eye on your queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;whereHas is a testament to the flexibility and power that Laravel's Eloquent offers. When used wisely, it can make your database queries clean, intuitive, and efficient.&lt;/p&gt;

&lt;p&gt;I hope you found this deep dive helpful. Always remember to optimize your queries and use the tools at your disposal to ensure the best performance. Happy coding, and stay curious!&lt;/p&gt;

&lt;p&gt;Dont miss the &lt;a href="https://dev.to/bytebricks/integrating-aws-simple-email-service-ses-with-laravel-a-comprehensive-guide-1lj3"&gt;Laravel AWS SES Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Resources&lt;br&gt;
&lt;a href="https://laravel.com/docs/10.x/eloquent-relationships#querying-relationship-existence"&gt;&lt;em&gt;Laravel Docs&lt;/em&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=ZEDUihpRQMM"&gt;&lt;em&gt;Great video explaining usage&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>tutorial</category>
      <category>sql</category>
      <category>api</category>
    </item>
  </channel>
</rss>
