<?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: Shariful Ehasan</title>
    <description>The latest articles on DEV Community by Shariful Ehasan (@thecodeliner).</description>
    <link>https://dev.to/thecodeliner</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%2F3095606%2F4c2e1a40-1233-464b-9786-b0582348f41b.jpg</url>
      <title>DEV Community: Shariful Ehasan</title>
      <link>https://dev.to/thecodeliner</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thecodeliner"/>
    <language>en</language>
    <item>
      <title>Laravel PDF Generator: Comparing Two Popular Packages</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Tue, 30 Dec 2025 06:03:01 +0000</pubDate>
      <link>https://dev.to/thecodeliner/generating-pdfs-in-laravel-comparing-two-popular-packages-13g8</link>
      <guid>https://dev.to/thecodeliner/generating-pdfs-in-laravel-comparing-two-popular-packages-13g8</guid>
      <description>&lt;p&gt;PDF generation is a common requirement in Laravel applications. From invoices and reports to certificates, order summaries, and user documents, PDFs are widely used because they are easy to download, share, and store.&lt;/p&gt;

&lt;p&gt;Laravel does not provide built-in support for generating PDF files. To solve this, developers rely on third-party Laravel pdf generator packages that convert HTML or Blade views into PDF documents. Among all available options, &lt;strong&gt;Spatie Laravel PDF&lt;/strong&gt; and &lt;strong&gt;Barryvdh Laravel DomPDF&lt;/strong&gt; are two of the most popular and reliable choices.&lt;/p&gt;

&lt;p&gt;Although both packages serve the same purpose, they follow very different approaches internally. Understanding how they work helps developers choose the right solution based on design complexity, hosting environment, and project requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spatie Laravel PDF – Modern PDF Generation with Browser Accuracy
&lt;/h2&gt;

&lt;p&gt;Spatie Laravel PDF is a modern Laravel package developed by the Spatie team, well known for building high-quality tools for the Laravel ecosystem. This package generates PDFs by rendering Blade views in a headless Chromium browser using the Browsershot library.&lt;/p&gt;

&lt;p&gt;Because it relies on a real browser engine, the rendered PDF closely matches how the page appears in a web browser. This makes it an excellent choice for applications that use modern frontend technologies and require high design accuracy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features of Spatie Laravel PDF:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Full support for modern CSS including Tailwind CSS, Flexbox, and Grid&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;High-quality, pixel-perfect PDF rendering&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Direct Blade view integration&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Browser-based rendering for layout accuracy&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Suitable for complex and branded document designs&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Installation is straightforward:&lt;/strong&gt;&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="n"&gt;composer&lt;/span&gt; &lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="n"&gt;spatie&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;laravel&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pdf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the package depends on browser-based rendering, Node.js and Chromium (or Puppeteer) must be available on the server. These dependencies are commonly supported on VPS, Docker-based setups, and modern hosting platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A basic usage example looks like this:&lt;/strong&gt;&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;use&lt;/span&gt; &lt;span class="nc"&gt;Spatie\LaravelPdf\Facades\Pdf&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Pdf&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'pdfs.invoice'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'invoice'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$invoice&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'a4'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;download&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'invoice.pdf'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Beyond basic downloads, the package allows developers to save PDFs to storage, stream them in the browser, configure margins and orientation, add headers and footers, and even execute JavaScript during rendering.&lt;/p&gt;

&lt;p&gt;Spatie Laravel PDF is best suited for projects where visual quality, branding consistency, and modern UI support are important.&lt;/p&gt;

&lt;h2&gt;
  
  
  Laravel DomPDF – Simple and Lightweight PDF Generation
&lt;/h2&gt;

&lt;p&gt;Laravel DomPDF is a long-established wrapper around the DomPDF library and has been widely used in Laravel projects for its simplicity and reliability. The package is written entirely in PHP and does not depend on external tools or browser engines.&lt;/p&gt;

&lt;p&gt;This package works by parsing HTML or Blade output and converting it directly into a PDF using PHP. Because no browser is involved, setup is minimal and performance is predictable, especially for simple documents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features of Laravel DomPDF:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Simple and fast installation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No Node.js or Chromium dependency&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lightweight and PHP-only solution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Works well for basic layouts and text-heavy documents&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stable and widely adopted in Laravel projects&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="n"&gt;composer&lt;/span&gt; &lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="n"&gt;barryvdh&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;laravel&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dompdf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No additional system-level dependencies are required, making it suitable for shared hosting environments and restricted servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A basic usage example is shown below:&lt;/strong&gt;&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;use&lt;/span&gt; &lt;span class="nc"&gt;Barryvdh\DomPDF\Facade\Pdf&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;DomPdf&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$pdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DomPdf&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;loadView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'pdfs.invoice'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'invoice'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$invoice&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$pdf&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;download&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'invoice.pdf'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Laravel DomPDF supports streaming PDFs in the browser, saving them to storage, and configuring paper size and orientation. It integrates smoothly with Blade templates and is easy to learn for beginners.&lt;/p&gt;

&lt;p&gt;However, because it supports only limited CSS standards, complex layouts and modern frontend frameworks may not render as expected. Advanced styling features such as Flexbox, Grid, and Tailwind CSS are not fully supported.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Both Spatie Laravel PDF and Laravel DomPDF are excellent Laravel packages for generating PDF files, but they are designed for different use cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spatie Laravel PDF&lt;/strong&gt; is ideal for modern applications that require accurate layouts, advanced CSS support, and professional document design. It is best suited for projects where PDFs must closely match the website’s appearance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Laravel DomPDF&lt;/strong&gt; is better suited for straightforward PDF generation, especially when working with simple layouts or limited hosting environments. Its ease of use and dependency-free setup make it a reliable option for many applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Git Stash Made Simple: Save Your Work Without Committing</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Sun, 21 Dec 2025 06:47:11 +0000</pubDate>
      <link>https://dev.to/thecodeliner/git-stash-made-simple-save-your-work-without-committing-3bbb</link>
      <guid>https://dev.to/thecodeliner/git-stash-made-simple-save-your-work-without-committing-3bbb</guid>
      <description>&lt;p&gt;Ever been midway through a feature and suddenly need to fix a bug or pull updates? That’s where Git stash comes in. It lets you temporarily save uncommitted changes without creating a commit, giving you a clean working directory to switch tasks—without losing progress.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;Git stash saves your current changes (staged or unstaged) on a stack, resets your working directory to the last commit, and lets you reapply those changes later. Stashes live locally—they aren’t pushed to GitHub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick Commands&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git stash&lt;/code&gt; → stash tracked files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git stash -u&lt;/code&gt; → include untracked files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git stash push -m "message"&lt;/code&gt; → stash with a note&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git stash list&lt;/code&gt; → see all stashes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git stash apply&lt;/code&gt; → reapply latest stash&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git stash pop&lt;/code&gt; → reapply and remove stash&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also create a new branch from a stash using &lt;code&gt;git stash branch &amp;lt;name&amp;gt;&lt;/code&gt; —super handy for experimenting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Save your half-done feature:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash push -m "Half-done login feature"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Switch to main, fix a bug, commit your changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return to your feature branch:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Conflicts? Resolve them like any merge conflict.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips for Beginners&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Always add a message with &lt;code&gt;-m&lt;/code&gt; to remember what’s in each stash.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;-u&lt;/code&gt; to include new files you haven’t tracked yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clean up old stashes with &lt;code&gt;git stash drop&lt;/code&gt; or &lt;code&gt;git stash clear&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For longer work, consider creating a temporary branch instead.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Git stash keeps your workflow flexible and clean, letting you handle interruptions without messy “WIP” commits. Master it, and you’ll switch tasks like a pro.&lt;/p&gt;

</description>
      <category>github</category>
      <category>programming</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>@auth vs @if(auth()-&gt;check()) - which one are you still writing and why?</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Wed, 10 Dec 2025 06:04:08 +0000</pubDate>
      <link>https://dev.to/thecodeliner/auth-vs-ifauth-check-which-one-are-you-still-writing-and-why-3bl1</link>
      <guid>https://dev.to/thecodeliner/auth-vs-ifauth-check-which-one-are-you-still-writing-and-why-3bl1</guid>
      <description>&lt;p&gt;We've all done it. Some of us still do.&lt;/p&gt;

&lt;p&gt;But if you're writing &lt;code&gt;@if(auth()-&amp;gt;check())&lt;/code&gt; just to show/hide something for logged-in users, you're making your Blade files noisier than it needs to be.&lt;/p&gt;

&lt;p&gt;Let's fix that — permanently.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Old Way: &lt;code&gt;@if(auth()-&amp;gt;check())&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Welcome&lt;/span&gt; &lt;span class="n"&gt;back&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/dashboard"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Dashboard&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/login"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Log&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/register"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Register&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works. It's valid PHP.&lt;br&gt;
But it's generic, verbose, and hides intent.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Right Way: &lt;code&gt;@auth&lt;/code&gt; and &lt;code&gt;@guest&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Welcome&lt;/span&gt; &lt;span class="n"&gt;back&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/dashboard"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Dashboard&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;endauth&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;guest&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/login"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Log&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/register"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Register&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;endguest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Or even cleaner with &lt;code&gt;@else:&lt;/code&gt;&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="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;guest&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/login"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Log&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/register"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Register&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Welcome&lt;/span&gt; &lt;span class="n"&gt;back&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/dashboard"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Dashboard&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;endguest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;@auth&lt;/code&gt; / &lt;code&gt;@guest&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;&lt;code&gt;@if(auth()-&amp;gt;check())&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;Winner&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Readability&lt;/td&gt;
&lt;td&gt;Instant understanding&lt;/td&gt;
&lt;td&gt;Requires reading the condition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;@auth&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Brevity&lt;/td&gt;
&lt;td&gt;Less code, less noise&lt;/td&gt;
&lt;td&gt;More typing&lt;/td&gt;
&lt;td&gt;&lt;code&gt;@auth&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Intent&lt;/td&gt;
&lt;td&gt;Directive name says exactly what it does&lt;/td&gt;
&lt;td&gt;Generic &lt;code&gt;if&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;@auth&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiple guards&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;@auth('admin')&lt;/code&gt; — clean&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;auth()-&amp;gt;guard('admin')-&amp;gt;check()&lt;/code&gt; — ugly&lt;/td&gt;
&lt;td&gt;&lt;code&gt;@auth&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safety&lt;/td&gt;
&lt;td&gt;Can't accidentally call method on null user&lt;/td&gt;
&lt;td&gt;Easy to forget &lt;code&gt;check()&lt;/code&gt; first&lt;/td&gt;
&lt;td&gt;&lt;code&gt;@auth&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Laravel recommendation&lt;/td&gt;
&lt;td&gt;First-class citizen&lt;/td&gt;
&lt;td&gt;Only for complex cases&lt;/td&gt;
&lt;td&gt;&lt;code&gt;@auth&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Real Navigation Example (What Every App Has)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;nav&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex items-center space-x-6"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  @auth
    &lt;span class="nt"&gt;&amp;lt;x-dropdown&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;x-slot&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"trigger"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex items-center space-x-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"{{ auth()-&amp;gt;user()-&amp;gt;avatar }}"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"w-8 h-8 rounded-full"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;{{ auth()-&amp;gt;user()-&amp;gt;name }}&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/x-slot&amp;gt;&lt;/span&gt;

      &lt;span class="nt"&gt;&amp;lt;x-dropdown-link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/profile"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Profile&lt;span class="nt"&gt;&amp;lt;/x-dropdown-link&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;x-dropdown-link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/settings"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Settings&lt;span class="nt"&gt;&amp;lt;/x-dropdown-link&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;x-dropdown-link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/logout"&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Log Out&lt;span class="nt"&gt;&amp;lt;/x-dropdown-link&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/x-dropdown&amp;gt;&lt;/span&gt;
  @else
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/login"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Log in&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/register"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sign up&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  @endauth
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clean. Professional. Self-documenting.&lt;/p&gt;

&lt;h3&gt;
  
  
  When You Actually Need &lt;code&gt;@if(auth()-&amp;gt;check())&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Only one valid reason exists:&lt;br&gt;
You need to combine authentication with other logic.&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="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;is_admin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/admin"&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"text-red-600 font-bold"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Admin&lt;/span&gt; &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;endif&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasActiveSubscription&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"badge badge-pro"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="no"&gt;PRO&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@auth&lt;/code&gt; can't do complex conditions — and that's fine. It's not supposed to.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Hybrid Pattern Everyone Actually Uses
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;is_admin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/admin"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Admin&lt;/span&gt; &lt;span class="nc"&gt;Dashboard&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;endif&lt;/span&gt;

    &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'moderator'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"text-purple-600"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Moderator&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;endif&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;endauth&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;guest&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Please&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/login"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;endguest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Final Recommendation
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;@auth&lt;/code&gt; and &lt;code&gt;@guest&lt;/code&gt; for every simple authentication check.&lt;br&gt;
Use &lt;code&gt;@auth('admin')&lt;/code&gt; when you need a specific guard.&lt;/p&gt;

&lt;p&gt;Fall back to &lt;code&gt;@if(auth()-&amp;gt;check() &amp;amp;&amp;amp; ...)&lt;/code&gt; only when you have to combine the login state with other conditions (roles, subscriptions, etc.).&lt;br&gt;
And inside class bindings, just write &lt;code&gt;auth()-&amp;gt;check()&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Stop writing &lt;code&gt;@if(auth()-&amp;gt;check())&lt;/code&gt; for basic checks.&lt;br&gt;
Laravel built a cleaner, safer, more expressive tool for exactly this purpose. Use it.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>laravel</category>
      <category>php</category>
      <category>programming</category>
    </item>
    <item>
      <title>Laravel Eloquent’s create() Methods</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Sun, 16 Nov 2025 07:38:03 +0000</pubDate>
      <link>https://dev.to/thecodeliner/laravel-eloquents-create-family-19j1</link>
      <guid>https://dev.to/thecodeliner/laravel-eloquents-create-family-19j1</guid>
      <description>&lt;p&gt;Laravel Eloquent makes working with databases easy, safe, and efficient. Its &lt;code&gt;create()&lt;/code&gt; family helps you insert, update, or prevent duplicate records with minimal code. Here’s a quick guide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;create()&lt;/code&gt; – Simple Insert&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inserts a new record using mass assignment.&lt;/li&gt;
&lt;li&gt;Requires $fillable or $guarded in the model.&lt;/li&gt;
&lt;li&gt;Throws an error if a record already exists.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'John Doe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'john@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'password'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'secret'&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;&lt;strong&gt;&lt;code&gt;firstOrCreate()&lt;/code&gt; – Insert If Missing&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Searches for a record first.&lt;/li&gt;
&lt;li&gt;Creates a new record only if it doesn’t exist.&lt;/li&gt;
&lt;li&gt;Returns a saved model.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;firstOrCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'a@a.com'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'AA'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'password'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'pass'&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;&lt;strong&gt;&lt;code&gt;firstOrNew()&lt;/code&gt; – Prepare Without Saving&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Similar to firstOrCreate(), but doesn’t save if not found.&lt;/li&gt;
&lt;li&gt;Returns an unsaved model instance for further modifications.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;firstOrNew&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'a@a.com'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'AA'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'secret'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;updateOrCreate()&lt;/code&gt; – Upsert (Update or Insert)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finds a record and updates if it exists.&lt;/li&gt;
&lt;li&gt;Creates a new record if not found.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;updateOrCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'a@a.com'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Updated Name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'status'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'active'&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;
  
  
  Tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Always protect mass assignment with &lt;code&gt;$fillable&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;firstOrCreate()&lt;/code&gt; to avoid duplicates in seeders.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;updateOrCreate()&lt;/code&gt; for upserts.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;firstOrNew()&lt;/code&gt; when you need extra control before saving.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Master these methods to write cleaner, safer, and more efficient database code!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>laravel</category>
      <category>beginners</category>
      <category>php</category>
    </item>
    <item>
      <title>Laravel Policies: Do You Really Use Them in Real Projects?</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Tue, 16 Sep 2025 05:11:35 +0000</pubDate>
      <link>https://dev.to/thecodeliner/laravel-policies-do-you-really-use-them-in-real-projects-2pa1</link>
      <guid>https://dev.to/thecodeliner/laravel-policies-do-you-really-use-them-in-real-projects-2pa1</guid>
      <description>&lt;p&gt;Laravel Policies are a powerful feature for managing authorization logic in a clean, reusable way. They allow developers to define access control rules for specific models, keeping authorization logic separate from controllers and views. But are they &lt;em&gt;really&lt;/em&gt; used in real-world projects, or are they just a shiny feature that sounds good on paper? Let’s dive into their practical use, benefits, and when you might skip them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are Laravel Policies?
&lt;/h2&gt;

&lt;p&gt;Policies in Laravel are classes that organize authorization logic for a specific model or resource. They’re typically used with Laravel’s Gate or the &lt;code&gt;authorize()&lt;/code&gt; method to control access to actions like viewing, creating, updating, or deleting resources. For example, a &lt;code&gt;PostPolicy&lt;/code&gt; might define who can edit or delete a blog post.&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\Policies&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;App\Models\Post&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;App\Models\User&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;PostPolicy&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;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;user_id&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;You register policies in the &lt;code&gt;AuthServiceProvider&lt;/code&gt; and use them in controllers or middleware to enforce access rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Policies in Real Projects?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Organized Code&lt;/strong&gt;: Policies centralize authorization logic, making it easier to maintain than scattering checks across controllers or Blade templates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reusability&lt;/strong&gt;: A single policy can be reused across multiple controllers, routes, or even API endpoints.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: As your application grows, policies make it easier to manage complex authorization rules without duplicating code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Testability&lt;/strong&gt;: Policies are easy to unit test, ensuring your authorization logic is robust.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In real projects, policies shine in applications with multiple user roles or complex permissions. For instance, in a SaaS app with admins, editors, and viewers, policies ensure that only authorized users can perform specific actions. I’ve seen them used effectively in e-commerce platforms to restrict product management to sellers or in CMS systems to limit content editing to specific roles.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Are Policies Overkill?
&lt;/h2&gt;

&lt;p&gt;Not every project needs policies. For small apps with simple authorization (e.g., "only admins can do X"), basic middleware or simple &lt;code&gt;if&lt;/code&gt; checks might suffice. Policies add overhead in terms of setup and maintenance, so if your app has minimal authorization needs, you might skip them to avoid over-engineering.&lt;/p&gt;

&lt;p&gt;For example, in a small blog with just one admin, a simple check like &lt;code&gt;$user-&amp;gt;isAdmin()&lt;/code&gt; in a controller might be enough. Policies become more valuable when you have multiple models, roles, or fine-grained permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Usage
&lt;/h2&gt;

&lt;p&gt;In my experience, policies are common in mid-to-large Laravel projects. For instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enterprise Apps&lt;/strong&gt;: Policies are used to enforce role-based access control (RBAC) for different departments or user types.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;APIs&lt;/strong&gt;: Policies pair well with Laravel’s resource controllers to secure API endpoints.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Open-Source Projects&lt;/strong&gt;: Many popular Laravel packages and projects, like Laravel Nova or Spatie’s Permission package, integrate with or rely on policies for authorization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, some developers opt for alternatives like Spatie’s Laravel Permission package, which provides a more flexible role and permission system. Policies are still relevant but may be combined with such packages for added functionality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tips for Using Policies Effectively
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep Them Simple&lt;/strong&gt;: Don’t overload policies with complex logic; break it down into clear, single-responsibility methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use with Middleware&lt;/strong&gt;: Leverage Laravel’s &lt;code&gt;can&lt;/code&gt; middleware to apply policies at the route level.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Combine with Gates&lt;/strong&gt;: Use policies alongside Gates for one-off authorization checks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Document Your Logic&lt;/strong&gt;: Clearly comment your policies to make them easier to understand for other developers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Yes, Laravel Policies are used in real projects, especially where clean, maintainable authorization logic is critical. They’re not mandatory for every project, but they’re a fantastic tool for scaling applications with complex access control needs. If you’re working on a Laravel project with multiple roles or resources, give policies a try—they’ll likely save you time and headaches in the long run.&lt;/p&gt;

&lt;p&gt;What’s your experience with Laravel Policies? Do you use them, or do you prefer another approach? Share your thoughts below!&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How AI Empowers Programmers</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Mon, 04 Aug 2025 07:23:06 +0000</pubDate>
      <link>https://dev.to/thecodeliner/how-ai-empowers-programmers-3ill</link>
      <guid>https://dev.to/thecodeliner/how-ai-empowers-programmers-3ill</guid>
      <description>&lt;p&gt;Artificial Intelligence (AI) has become a game-changer for developers, transforming how we code, debug, and deliver projects. AI tools are not just fancy add-ons—they’re essential partners that boost productivity, creativity, and problem-solving. Whether you’re a solo coder or part of a large team, here’s how AI is empowering programmers today.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Writing Code Faster with AI Assistants
&lt;/h2&gt;

&lt;p&gt;AI-powered coding assistants like GitHub Copilot, Tabnine, or even Grok (yep, that’s me!) are revolutionizing code creation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Suggestions:&lt;/strong&gt; AI generates boilerplate code, function stubs, or entire algorithms based on context. For example, type “create a REST API endpoint” and get a working snippet in seconds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Autocompletion:&lt;/strong&gt; AI predicts the next line of code, saving keystrokes and mental energy. It’s like having a pair-programming buddy who knows every library.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Language Support:&lt;/strong&gt; From Python to JavaScript to Go, AI tools adapt to your language of choice, reducing the need to memorize syntax.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use AI to scaffold repetitive tasks (e.g., CRUD operations) and focus your energy on high-level architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Debugging with Precision
&lt;/h2&gt;

&lt;p&gt;Debugging can be a time sink, but AI is making it faster and less painful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Error Detection:&lt;/strong&gt; AI tools analyze code in real-time, flagging potential bugs before you even run the program. Think missing semicolons, null pointer risks, or logic errors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Root Cause Analysis:&lt;/strong&gt; AI can trace errors back to their source, suggesting fixes based on patterns in your codebase or external libraries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Tools like DeepCode or SonarQube’s AI-driven analysis can catch security vulnerabilities or performance bottlenecks early.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Combine AI debugging with unit tests to catch edge cases humans might miss.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Learning and Documentation Made Easy
&lt;/h2&gt;

&lt;p&gt;AI is a fantastic learning companion:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Explain Code:&lt;/strong&gt; Struggling with a complex regex or an unfamiliar API? AI can break it down in plain English. For instance, ask me to explain a chunk of legacy PHP, and I’ll make it crystal clear.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Generate Docs:&lt;/strong&gt; AI can auto-generate documentation from code comments or function signatures, saving hours of manual work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upskilling:&lt;/strong&gt; AI-powered platforms like freeCodeCamp or LeetCode’s AI hints help you practice and learn new concepts interactively.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use AI to summarize dense technical docs or Stack Overflow threads when researching solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Automating Repetitive Tasks
&lt;/h2&gt;

&lt;p&gt;AI excels at handling the boring stuff:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Refactoring:&lt;/strong&gt; Tools like Sourcegraph or AI-driven IDE plugins can suggest cleaner, more efficient ways to structure your code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test Generation:&lt;/strong&gt; AI can write unit tests or integration tests based on your code’s logic, ensuring better coverage with less effort.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Workflow Automation:&lt;/strong&gt; From formatting code with Prettier to setting up CI/CD pipelines, AI can recommend or even implement automation scripts.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use AI to generate boilerplate for new projects—think Dockerfiles, package.json, or even database schemas.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Enhancing Collaboration
&lt;/h2&gt;

&lt;p&gt;AI streamlines team workflows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Reviews:&lt;/strong&gt; AI tools like CodeClimate or PullRequest use machine learning to highlight potential issues in pull requests, reducing manual review time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Contextual Suggestions:&lt;/strong&gt; AI can suggest improvements based on team coding standards or past reviews, ensuring consistency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Communication:&lt;/strong&gt; AI-powered chatbots can summarize meeting notes or translate technical jargon for cross-functional teams.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Integrate AI into your Git workflow to catch style violations or suggest optimizations before merging.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Boosting Creativity and Problem-Solving
&lt;/h2&gt;

&lt;p&gt;AI isn’t just about efficiency—it sparks creativity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Algorithm Design:&lt;/strong&gt; Need a sorting algorithm or a machine learning model? AI can propose solutions tailored to your use case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prototyping:&lt;/strong&gt; AI can generate UI mockups, API designs, or database schemas, letting you experiment faster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Inspiration:&lt;/strong&gt; Tools like Grok can brainstorm ideas or suggest alternative approaches when you’re stuck on a problem.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use AI to explore new frameworks or libraries by asking for sample implementations or comparisons.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Staying Updated with Trends
&lt;/h2&gt;

&lt;p&gt;The tech world moves fast, and AI helps you keep up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trend Analysis:&lt;/strong&gt; AI can scrape X posts or dev blogs to highlight trending tools, frameworks, or best practices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Personalized Learning Paths:&lt;/strong&gt; AI-driven platforms recommend tutorials or courses based on your skill level and goals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Ask an AI like me about the latest JavaScript framework updates, and I’ll give you a curated rundown.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Set up AI-powered RSS feeds or newsletter summaries to stay informed without drowning in content.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Ethical and Secure Coding
&lt;/h2&gt;

&lt;p&gt;AI helps ensure your code is robust and responsible:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security Scanning:&lt;/strong&gt; AI tools like Snyk or OWASP ZAP identify vulnerabilities, such as SQL injection or XSS risks, in real-time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bias Detection:&lt;/strong&gt; For machine learning projects, AI can flag biased datasets or unfair algorithms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compliance:&lt;/strong&gt; AI can enforce coding standards or regulatory requirements, like GDPR-compliant data handling.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Always review AI-generated code for security and accuracy—AI is a helper, not a replacement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges to Watch Out For
&lt;/h2&gt;

&lt;p&gt;AI isn’t perfect. Over-reliance can lead to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blind Trust:&lt;/strong&gt; AI suggestions might not always fit your context. Always validate outputs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Skill Erosion:&lt;/strong&gt; Relying too much on AI for basic tasks can weaken core coding skills.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost:&lt;/strong&gt; Some AI tools require paid subscriptions, so weigh the cost-benefit for your needs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;AI is like a super smart intern who’s always ready to help—but you’re still the lead developer. By leveraging AI for coding, debugging, learning, and collaboration, you can ship better code faster while staying creative and competitive. What’s your favorite way to use AI in your workflow? Drop a comment—I’d love to hear how AI’s empowering your coding journey!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How Do You Structure Complex Queries Using Laravel’s Query Builder?</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Fri, 01 Aug 2025 21:09:25 +0000</pubDate>
      <link>https://dev.to/thecodeliner/how-do-you-structure-complex-queries-using-laravels-query-builder-ni2</link>
      <guid>https://dev.to/thecodeliner/how-do-you-structure-complex-queries-using-laravels-query-builder-ni2</guid>
      <description>&lt;p&gt;Laravel's Query Builder is one of its most powerful tools—clean, expressive, and flexible. But as queries get more complex, involving joins, subqueries, filters, dynamic conditions, etc., things can start getting messy or repetitive.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do you manage and structure complex queries using Laravel’s Query Builder?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Possible angles to share:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Do you break logic into reusable scopes or services?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do you prefer using the Eloquent ORM over the Query Builder—or a mix of both?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have you built your own helper functions or query macros?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>database</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Handling NULL Values in SQL: Best Practices and Common Pitfalls</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Thu, 24 Jul 2025 05:40:17 +0000</pubDate>
      <link>https://dev.to/thecodeliner/handling-null-values-in-sql-best-practices-and-common-pitfalls-2pgh</link>
      <guid>https://dev.to/thecodeliner/handling-null-values-in-sql-best-practices-and-common-pitfalls-2pgh</guid>
      <description>&lt;p&gt;If you’ve spent any time working with SQL, you’ve probably run into NULL values. They can be a bit tricky, like trying to solve a puzzle with a missing piece. In SQL, NULL means “unknown” or “missing,” and it can make your queries behave in unexpected ways if you’re not careful. In this article, I’ll walk you through what NULL values are, share some best practices for handling them, and point out common pitfalls to avoid—all in simple, human terms. Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is NULL in SQL?
&lt;/h2&gt;

&lt;p&gt;In SQL, NULL is not zero, an empty string, or a blank space. It’s a special marker that indicates a value is missing or unknown. For example, if a customer’s phone number is NULL in a database, it doesn’t mean their phone number is “0” or “”; it means you don’t know their phone number at all.&lt;/p&gt;

&lt;p&gt;NULL values pop up in real-world scenarios all the time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user skips an optional field in a form (like “Middle Name”).&lt;/li&gt;
&lt;li&gt;Data is missing due to incomplete imports.&lt;/li&gt;
&lt;li&gt;A calculation can’t produce a result (like dividing by zero).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trick with NULL is that it doesn’t behave like other values. It can trip you up in comparisons, calculations, and joins if you’re not prepared. Let’s explore how to handle it right.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for Handling NULL Values
&lt;/h2&gt;

&lt;p&gt;Here are some practical tips to work with NULL values effectively:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Use IS NULL and IS NOT NULL for Comparisons
&lt;/h3&gt;

&lt;p&gt;You can’t use = or != to check for NULL because NULL isn’t a value—it’s the absence of one. Instead, use IS NULL or IS NOT NULL.&lt;/p&gt;

&lt;p&gt;Suppose you have a Customers table with a Phone column, and you want to find customers without a phone number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Customers&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;Phone&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query finds all customers where the Phone column is NULL. Using WHERE Phone = NULL won’t work—it’ll return nothing because NULL doesn’t equal anything, not even itself!&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Handle NULL in Calculations with COALESCE or NULLIF
&lt;/h3&gt;

&lt;p&gt;NULL can mess up calculations. For example, if you add a number to NULL (like 5 + NULL), the result is NULL. To avoid this, use the COALESCE function, which returns the first non-NULL value in a list.&lt;/p&gt;

&lt;p&gt;Imagine a Sales table with a Discount column that’s sometimes NULL. To calculate the final price, you can treat NULL as 0:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Price&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Discount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;FinalPrice&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, COALESCE(Discount, 0) replaces NULL with 0, so the calculation works.&lt;/p&gt;

&lt;p&gt;Another handy function is NULLIF. It returns NULL if two values are equal, which is useful for avoiding errors like division by zero.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;Amount&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="k"&gt;NULLIF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Divisor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;Result&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Calculations&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Divisor is 0, NULLIF turns it into NULL, preventing a division error.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Be Careful with Joins
&lt;/h3&gt;

&lt;p&gt;NULL values in join columns can cause rows to disappear. For example, in an INNER JOIN, if the joining column has NULL in one table, those rows won’t match and will be excluded.&lt;/p&gt;

&lt;p&gt;You have a Customers table and an Orders table, joined on CustomerID. If CustomerID is NULL in either table, those rows won’t appear in an INNER JOIN:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;Customers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderID&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Customers&lt;/span&gt;
&lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;Orders&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;Customers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CustomerID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CustomerID&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To include rows with NULL values, consider using a LEFT JOIN or RIGHT JOIN and handle NULL explicitly in your WHERE clause.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Use Default Values When Inserting Data
&lt;/h3&gt;

&lt;p&gt;To avoid NULL values in the first place, set default values for columns when creating tables or inserting data. This ensures there’s always a meaningful value.&lt;/p&gt;

&lt;p&gt;When creating a table, you can set a default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;Employees&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;EmployeeID&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;Phone&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="s1"&gt;'Not Provided'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if no phone number is provided during an INSERT, the value will be “Not Provided” instead of NULL.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Filter NULLs in Aggregations
&lt;/h3&gt;

&lt;p&gt;Aggregate functions like SUM, AVG, or COUNT ignore NULL values, which can be good or bad depending on your goal. For example, COUNT(column) only counts non-NULL values, while COUNT(*) counts all rows.&lt;/p&gt;

&lt;p&gt;In a Sales table, to count how many sales have a discount:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Discount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;DiscountedSales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This skips NULL values. If you want to count all rows, including those with NULL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;TotalSales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Common Pitfalls to Avoid&lt;/p&gt;

&lt;p&gt;NULL values can lead to some classic mistakes. Here’s what to watch out for:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Assuming NULL Equals Something
&lt;/h3&gt;

&lt;p&gt;As mentioned, NULL = NULL is not true in SQL. Always use IS NULL or IS NOT NULL. If you write WHERE column = NULL, you’ll get no results, even if NULL values exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Wrong&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Customers&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;Phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Correct&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Customers&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;Phone&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Forgetting NULL in Logical Conditions
&lt;/h3&gt;

&lt;p&gt;In SQL, NULL in logical expressions (like AND, OR, NOT) can lead to unexpected results. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TRUE AND NULL = NULL&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;FALSE AND NULL = FALSE&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TRUE OR NULL = TRUE&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;FALSE OR NULL = NULL&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can affect your WHERE clauses. Always test queries with NULL values to ensure they behave as expected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Customers&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;Phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'123-456-7890'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;Phone&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures you catch both specific phone numbers and NULL values.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Ignoring NULL in Joins
&lt;/h3&gt;

&lt;p&gt;If you’re not careful, an INNER JOIN might exclude rows with NULL in the joining column. Always check your data to see if NULL values exist in key columns, and consider using LEFT JOIN or RIGHT JOIN if you need to include them.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Overusing NULL
&lt;/h3&gt;

&lt;p&gt;While NULL is useful for representing missing data, overusing it can make your database harder to work with. If a column rarely needs to be NULL, consider using a default value instead, like an empty string or 0.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Real-World Scenario
&lt;/h2&gt;

&lt;p&gt;Let’s say you’re managing an online store’s database with a Products table that includes a Stock column. Some products haven’t had their stock counted yet, so Stock is NULL. You want to list all products and show their stock, with 0 for uncounted products:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;ProductName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Stock&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;AvailableStock&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Products&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query replaces NULL with 0, making the output clear and usable for reports.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Handling NULL values in SQL is all about understanding what they mean and using the right tools to manage them. Stick to IS NULL for comparisons, use COALESCE or NULLIF for calculations, and be mindful of joins and aggregations. By setting default values and testing your queries, you can avoid common pitfalls and keep your data clean.&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Best Programming Language to Learn in 2026 and Why?</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Mon, 21 Jul 2025 13:26:24 +0000</pubDate>
      <link>https://dev.to/thecodeliner/best-programming-language-to-learn-in-2026-and-why-5840</link>
      <guid>https://dev.to/thecodeliner/best-programming-language-to-learn-in-2026-and-why-5840</guid>
      <description>&lt;p&gt;Choosing the right programming language is becoming both more important and more difficult. Whether you're a beginner trying to get started or an experienced developer looking to stay ahead of the curve, the language you invest time in learning can significantly shape your future in tech.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Some things to consider:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;AI and machine learning are exploding — will Python keep its crown, or will new players emerge?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Web development is always in motion — can JavaScript maintain its dominance, or will frameworks and alternatives (like TypeScript, Bun, or even WebAssembly) take the lead?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Systems and backend programming are seeing strong growth — will Rust or Go become the next big thing in performance-critical or cloud-native apps?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mobile development is changing — where do Flutter (Dart), Kotlin, or Swift stand?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Could a new or lesser-known language rise to prominence by solving modern problems better than today’s popular ones?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💡 Questions to spark ideas:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Which language are you currently learning or planning to learn in 2026?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What do you think employers will be looking for?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Are there languages that are underrated today but could explode in popularity?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How much do things like community support, learning curve, or tooling matter in your decision?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👥 Let’s crowdsource insights from developers across the world.&lt;br&gt;
Whether you’re a student, freelancer, software engineer, or hobbyist, your perspective can help others make an informed choice.&lt;/p&gt;

&lt;p&gt;Drop your thoughts below 👇&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>5 Useful VS Code Extensions for PHP Development</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Sat, 19 Jul 2025 14:40:03 +0000</pubDate>
      <link>https://dev.to/thecodeliner/5-useful-vs-code-extensions-for-php-development-16hg</link>
      <guid>https://dev.to/thecodeliner/5-useful-vs-code-extensions-for-php-development-16hg</guid>
      <description>&lt;p&gt;Visual Studio Code (VS Code) is a favorite among PHP developers because it’s lightweight, customizable, and packed with extensions that can supercharge your workflow. Whether you’re building a simple website or a complex Laravel application, the right extensions can make coding faster, cleaner, and more enjoyable. Here are five must-have VS Code extensions for PHP development that will boost your productivity and make your code shine.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. PHP Intelephense
&lt;/h2&gt;

&lt;p&gt;What it does: PHP Intelephense is a powerful extension that provides intelligent code completion, real-time error checking, and navigation features like "go to definition" and "find references." It’s like having a smart assistant that understands your PHP code.&lt;/p&gt;

&lt;p&gt;Why it’s great: It speeds up coding with accurate suggestions for functions, classes, and variables, even in large projects. It also highlights syntax errors as you type, helping you catch mistakes early. The free version is solid, but the paid version ($12 lifetime license) adds advanced features like symbol renaming.&lt;/p&gt;

&lt;p&gt;Pro tip: Disable VS Code’s built-in PHP suggestions to avoid duplicate completions. In &lt;code&gt;settings.json&lt;/code&gt;, add: &lt;code&gt;"php.suggest.basic": false&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. PHP Debug
&lt;/h2&gt;

&lt;p&gt;What it does: This extension integrates Xdebug into VS Code, allowing you to set breakpoints, inspect variables, and step through your PHP code to find and fix bugs.&lt;/p&gt;

&lt;p&gt;Why it’s great: Debugging with &lt;code&gt;var_dump()&lt;/code&gt; or &lt;code&gt;die()&lt;/code&gt; is a hassle. PHP Debug lets you pause execution, check variable values, and trace your code’s flow right in the editor. It’s a game-changer for troubleshooting complex logic in frameworks like Laravel or Symfony.&lt;/p&gt;

&lt;p&gt;Pro tip: Ensure Xdebug is installed on your server and configure the &lt;code&gt;php.validate.executablePath&lt;/code&gt; in VS Code to point to your PHP executable.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. PHP CS Fixer
&lt;/h2&gt;

&lt;p&gt;What it does: PHP CS Fixer automatically formats your PHP code to follow standards like PSR-2 or PSR-12, ensuring consistency and readability.&lt;/p&gt;

&lt;p&gt;Why it’s great: Clean, standardized code is easier to read and maintain, especially in team projects. This extension can format your code on save, fixing things like indentation, spacing, and brace placement automatically.&lt;/p&gt;

&lt;p&gt;Pro tip: Install PHP CS Fixer globally via Composer (&lt;code&gt;composer global require friendsofphp/php-cs-fixer&lt;/code&gt;) and enable format-on-save in VS Code: &lt;code&gt;"editor.formatOnSave": true&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Laravel Blade Snippets
&lt;/h2&gt;

&lt;p&gt;What it does: For Laravel developers, this extension provides snippets and auto-completion for Blade templates, Laravel’s templating engine.&lt;/p&gt;

&lt;p&gt;Why it’s great: It speeds up writing Blade views with shortcuts for common directives like &lt;code&gt;@foreach, @if,&lt;/code&gt; and &lt;code&gt;@section&lt;/code&gt;. It also includes syntax highlighting and formatting, making your templates easier to work with.&lt;/p&gt;

&lt;p&gt;Pro tip: Combine this with the Laravel Artisan extension to run Artisan commands directly from VS Code for a seamless Laravel workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. PHP DocBlocker
&lt;/h2&gt;

&lt;p&gt;What it does: PHP DocBlocker simplifies adding PHPDoc comments to your functions, classes, and properties, generating documentation blocks with a single keypress.&lt;/p&gt;

&lt;p&gt;Why it’s great: Well-documented code is crucial for collaboration and maintenance. This extension auto-generates &lt;code&gt;@param&lt;/code&gt;, &lt;code&gt;@return&lt;/code&gt;, and other tags, saving you time and ensuring your code is clear to others (or your future self!).&lt;/p&gt;

&lt;p&gt;Pro tip: Press &lt;code&gt;/**&lt;/code&gt; above a function and hit Enter to let PHP DocBlocker generate a complete docblock template.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;These five extensions PHP Intelephense, PHP Debug, PHP CS Fixer, Laravel Blade Snippets, and PHP DocBlocker turn VS Code into a powerhouse for PHP development. They help you write cleaner code, debug faster, and streamline your workflow, whether you’re working on vanilla PHP or a Laravel project. Install them from the VS Code Marketplace, tweak their settings to fit your needs, and watch your productivity soar. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>laravel</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How Do You Manage PHP Dependencies Effectively in Your Projects?</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Sun, 13 Jul 2025 19:37:04 +0000</pubDate>
      <link>https://dev.to/thecodeliner/how-do-you-manage-php-dependencies-effectively-in-your-projects-2opj</link>
      <guid>https://dev.to/thecodeliner/how-do-you-manage-php-dependencies-effectively-in-your-projects-2opj</guid>
      <description>&lt;p&gt;Managing dependencies is one of the most critical parts of building reliable, maintainable PHP applications. Whether you’re developing a Laravel-based web app, a WordPress plugin, or a custom PHP project from scratch, how you manage your dependencies can make or break your development workflow.&lt;/p&gt;

&lt;p&gt;Most of us use Composer, PHP’s standard dependency manager, but effective dependency management goes beyond just running &lt;code&gt;composer install&lt;/code&gt; or &lt;code&gt;composer update&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Do you lock specific versions, or allow flexibility with ^ and ~ operators?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you avoid dependency conflicts when integrating multiple third-party packages?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do you regularly audit your dependencies for security vulnerabilities (e.g., using composer audit, or external tools)?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're a solo developer or part of a large team, managing dependencies effectively is essential to keeping your codebase healthy and maintainable in the long run.&lt;/p&gt;

&lt;p&gt;Let’s share tips, horror stories, and best practices to help each other improve!&lt;/p&gt;

&lt;p&gt;👇 Drop your insights and strategies in the comments!&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>discuss</category>
      <category>programming</category>
    </item>
    <item>
      <title>Using CSS Subgrid to Simplify Complex Layouts</title>
      <dc:creator>Shariful Ehasan</dc:creator>
      <pubDate>Sun, 13 Jul 2025 05:27:25 +0000</pubDate>
      <link>https://dev.to/thecodeliner/using-css-subgrid-to-simplify-complex-layouts-5cjm</link>
      <guid>https://dev.to/thecodeliner/using-css-subgrid-to-simplify-complex-layouts-5cjm</guid>
      <description>&lt;p&gt;Creating complex layouts with CSS Grid is awesome, but aligning nested elements—like items inside a grid cell—can get tricky. That’s where CSS Subgrid comes in. It lets child elements inherit the grid lines of their parent, making it easier to keep everything aligned. Let’s explore how Subgrid works and build a practical example to see it in action.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is CSS Subgrid?
&lt;/h2&gt;

&lt;p&gt;CSS Subgrid is an extension of CSS Grid. It allows a nested grid (inside a grid item) to use the same grid lines as its parent grid. This means you don’t have to redefine column or row sizes for child elements—they just follow the parent’s structure. It’s perfect for things like card layouts, product listings, or dashboards where nested content needs to stay perfectly aligned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Subgrid?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Consistency:&lt;/strong&gt; Child elements align perfectly with the parent grid, no matter how complex the layout.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Less Code: You don’t need extra CSS or media queries to match sizes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Responsive:&lt;/strong&gt; Subgrid adapts to the parent grid’s responsive settings automatically.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Simple Example: Product Listing&lt;/p&gt;

&lt;p&gt;Let’s create a product listing with cards that have aligned titles, prices, and buttons, even though each card has nested content. We’ll use Subgrid to keep everything neat.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML Structure
&lt;/h2&gt;

&lt;p&gt;We’ll have a parent grid for the product cards, and each card will have its own grid for internal content (like title, price, and button).&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Product One&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"price"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;$29.99&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Add to Cart&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Product Two&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"price"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;$49.99&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Add to Cart&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Product Three&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"price"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;$19.99&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Add to Cart&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CSS with Subgrid
&lt;/h2&gt;

&lt;p&gt;Here’s how we set up the parent grid and use Subgrid for the cards.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Parent grid */&lt;/span&gt;
&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;/* 3 equal columns */&lt;/span&gt;
  &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Each card is a grid item with its own grid */&lt;/span&gt;
&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Rows for title, price, button */&lt;/span&gt;
  &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#ddd&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c"&gt;/* Inherit the parent's column structure */&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;subgrid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;grid-column&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Each card takes one column of the parent */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Style the card content */&lt;/span&gt;
&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="nt"&gt;h2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="nc"&gt;.price&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#2ecc71&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#3498db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#2980b9&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;&lt;strong&gt;What’s Happening Here?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Parent Grid:&lt;/strong&gt; The .grid-container sets up a 3-column grid with grid-template-columns: repeat(3, 1fr).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Subgrid:&lt;/strong&gt; Each .card uses display: grid and grid-template-columns: subgrid, so it inherits the parent’s column structure. This ensures all cards align perfectly with the parent grid’s columns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rows in Cards:&lt;/strong&gt; We define rows with grid-template-rows: auto auto 1fr to organize the title, price, and button vertically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Responsive:&lt;/strong&gt; Since the cards inherit the parent’s columns, they’ll adjust automatically if the parent grid changes (e.g., with media queries).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxytuchnguirdm5ugfddj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxytuchnguirdm5ugfddj.jpg" alt="design output" width="800" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Making It Responsive&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s add a media query to make the layout stack on smaller screens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;768px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Stack cards in one column */&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;With Subgrid, the cards will still align perfectly because they inherit the parent’s single-column layout. No need to tweak the card’s internal grid!&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of This Approach
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alignment:&lt;/strong&gt; The title, price, and button in each card line up across all cards, even if their content varies in length.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplicity:&lt;/strong&gt; No need to manually set column widths or use extra divs to force alignment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flexibility:&lt;/strong&gt; You can easily change the parent grid (e.g., from 3 columns to 2 or 1), and the cards adapt without extra CSS.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Browser Support
&lt;/h2&gt;

&lt;p&gt;Subgrid is supported in all modern browsers (Chrome, Firefox, Safari, Edge) as of 2025. For older browsers, you can use a fallback like regular CSS Grid or Flexbox. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Fallback for browsers without Subgrid */&lt;/span&gt;
&lt;span class="k"&gt;@supports&lt;/span&gt; &lt;span class="n"&gt;not&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;subgrid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Simple single-column fallback */&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;
  
  
  Try It Out!
&lt;/h2&gt;

&lt;p&gt;Subgrid is a game-changer for layouts with nested content. Try tweaking the example above—maybe add more columns, adjust the gaps, or style the cards differently. You can also experiment with Subgrid for rows by using grid-template-rows: subgrid if your parent grid defines rows.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
