<?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>Forem: Arafat Hossain Ar</title>
    <description>The latest articles on Forem by Arafat Hossain Ar (@arafatweb).</description>
    <link>https://forem.com/arafatweb</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%2F695640%2F11046860-b16c-4262-9ed3-e74e0b948ec0.jpg</url>
      <title>Forem: Arafat Hossain Ar</title>
      <link>https://forem.com/arafatweb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/arafatweb"/>
    <language>en</language>
    <item>
      <title>How to Use AI Without Ruining Your Programming Skills</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Wed, 18 Feb 2026 08:25:55 +0000</pubDate>
      <link>https://forem.com/arafatweb/how-to-use-ai-without-ruining-your-programming-skills-2538</link>
      <guid>https://forem.com/arafatweb/how-to-use-ai-without-ruining-your-programming-skills-2538</guid>
      <description>&lt;p&gt;AI tools are everywhere now. From code suggestions to instant bug fixes, it feels like you can build things faster than ever. For many developers, especially juniors, AI looks like the perfect shortcut.&lt;/p&gt;

&lt;p&gt;When I first started using AI while coding, it felt helpful and dangerous at the same time. Helpful because problems got solved quickly. Dangerous because I noticed I was thinking less and pasting more.&lt;/p&gt;

&lt;p&gt;In this blog, I will explain how to use AI &lt;strong&gt;as a learning partner instead of a replacement&lt;/strong&gt;, so your programming skills grow instead of slowly fading away.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Table of Contents&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Why AI Feels So Powerful&lt;/li&gt;
&lt;li&gt;Where AI Actually Helps Developers&lt;/li&gt;
&lt;li&gt;How AI Can Quietly Harm Your Skills&lt;/li&gt;
&lt;li&gt;Rules for Using AI the Right Way&lt;/li&gt;
&lt;li&gt;A Real World Analogy&lt;/li&gt;
&lt;li&gt;Practical AI Usage Examples&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why AI Feels So Powerful&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;AI tools feel powerful because they remove friction.&lt;/p&gt;

&lt;p&gt;You write a prompt, and suddenly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Errors are explained&lt;/li&gt;
&lt;li&gt;Code is generated&lt;/li&gt;
&lt;li&gt;Logic is suggested&lt;/li&gt;
&lt;li&gt;Bugs disappear&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This creates a false sense of mastery. Things work, but you may not fully understand why they work. That gap is where skills quietly weaken.&lt;/p&gt;

&lt;p&gt;AI feels fast. Learning is slow. Most people choose speed without realizing the cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Where AI Actually Helps Developers&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;AI is not the enemy. Used correctly, it can make you a better developer.&lt;/p&gt;

&lt;p&gt;AI is genuinely useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Explaining unfamiliar concepts in simple language&lt;/li&gt;
&lt;li&gt;Refactoring code after you write it&lt;/li&gt;
&lt;li&gt;Pointing out edge cases you missed&lt;/li&gt;
&lt;li&gt;Summarizing documentation&lt;/li&gt;
&lt;li&gt;Reviewing logic for readability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Explain why this loop is slow and how to improve it”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;is very different from asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Write the whole solution for me”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One builds understanding. The other replaces it.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How AI Can Quietly Harm Your Skills&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The danger is not obvious at first.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;You stop struggling&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Struggle is where learning happens. If AI solves every problem instantly, your brain never builds problem-solving muscles.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;You stop debugging&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Debugging teaches you how systems behave under pressure. Skipping it removes one of the most important developer skills.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;You lose architectural thinking&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;AI is good at small solutions. It is not responsible for your system design. If you rely on it too much, your big-picture thinking weakens.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;You become prompt-dependent&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you cannot code without asking AI first, your confidence and independence disappear.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Rules for Using AI the Right Way&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;These rules are simple, but powerful.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rule 1: Think First, Ask Second&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Always try to solve the problem yourself first. Even a bad attempt is valuable.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rule 2: Ask for Explanations, Not Solutions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ask AI to explain why something works instead of generating full code.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rule 3: Rewrite AI Code in Your Own Words&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If AI gives code, rewrite it manually. If you cannot rewrite it, you did not understand it.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rule 4: Never Skip Fundamentals&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;AI does not replace understanding loops, memory, databases, or networking. You still need those foundations.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Rule 5: Debug Without AI Sometimes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Force yourself to debug issues without AI. This keeps your instincts sharp.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A Real World Analogy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Think of AI like a calculator.&lt;/p&gt;

&lt;p&gt;A calculator is useful, but if you never learn basic math, you will not understand whether the result makes sense.&lt;/p&gt;

&lt;p&gt;AI is the same. It can assist, but it cannot replace understanding. If you trust it blindly, you lose the ability to judge correctness.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Practical AI Usage Examples&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Good AI Usage&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;“Explain why this query is slow”&lt;/li&gt;
&lt;li&gt;“What edge cases should I consider here?”&lt;/li&gt;
&lt;li&gt;“Can you review this code for readability?”&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Bad AI Usage&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;“Build the entire feature for me”&lt;/li&gt;
&lt;li&gt;“Fix this without explaining why”&lt;/li&gt;
&lt;li&gt;“Write production code I do not understand”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The difference is intention. Learning-focused prompts grow skills. Shortcut-focused prompts weaken them.&lt;/p&gt;

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

&lt;p&gt;AI is not replacing developers. It is exposing how developers learn.&lt;/p&gt;

&lt;p&gt;If you use AI to think less, your skills will decline. If you use AI to understand more, your skills will grow faster than before.&lt;/p&gt;

&lt;p&gt;The goal is not to avoid AI. The goal is to stay mentally involved while using it.&lt;/p&gt;

&lt;p&gt;AI should feel like a senior developer sitting next to you, explaining things. The moment it feels like a crutch, you are using it the wrong way.&lt;/p&gt;

&lt;p&gt;The future belongs to developers who can think, not just prompt.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Is PHP Still a Valuable Programming Language in 2026?</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Tue, 27 Jan 2026 05:44:19 +0000</pubDate>
      <link>https://forem.com/arafatweb/is-php-still-a-valuable-programming-language-in-2026-3449</link>
      <guid>https://forem.com/arafatweb/is-php-still-a-valuable-programming-language-in-2026-3449</guid>
      <description>&lt;p&gt;PHP is one of those programming languages everyone seems to have an opinion about. Some say it is outdated. Some say it is dying. Others quietly keep building real products with it every single day.&lt;/p&gt;

&lt;p&gt;When I first started with PHP, I also wondered whether learning it was a good long-term decision. With new languages and frameworks appearing every year, it is a fair question to ask.&lt;/p&gt;

&lt;p&gt;In this blog, I will break down whether PHP is still a valuable programming language in 2026, using real-world context instead of internet noise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Why People Think PHP Is Dying&lt;/li&gt;
&lt;li&gt;Where PHP Is Still Strong&lt;/li&gt;
&lt;li&gt;How PHP Has Evolved&lt;/li&gt;
&lt;li&gt;PHP in Real Production Systems&lt;/li&gt;
&lt;li&gt;Career Perspective for Developers&lt;/li&gt;
&lt;li&gt;When PHP Is a Bad Choice&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why People Think PHP Is Dying
&lt;/h2&gt;

&lt;p&gt;PHP has been around for a long time, and that alone makes people suspicious. Many developers associate PHP with old codebases, messy scripts, and poor practices from the past.&lt;/p&gt;

&lt;p&gt;Some common reasons people think PHP is no longer relevant:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They worked with legacy PHP code and had a bad experience&lt;/li&gt;
&lt;li&gt;They compare PHP to newer languages without context&lt;/li&gt;
&lt;li&gt;They assume popularity on social media equals real-world usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The truth is, most of these opinions come from outdated experiences, not modern PHP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where PHP Is Still Strong
&lt;/h2&gt;

&lt;p&gt;PHP still dominates areas that actually matter in production.&lt;/p&gt;

&lt;p&gt;It powers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A large percentage of the web&lt;/li&gt;
&lt;li&gt;Content-heavy platforms&lt;/li&gt;
&lt;li&gt;Backend systems for SaaS products&lt;/li&gt;
&lt;li&gt;CMS-driven businesses&lt;/li&gt;
&lt;li&gt;APIs and internal tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Frameworks like Laravel have changed how PHP applications are structured, tested, and maintained. Modern PHP projects look nothing like the old scripts people complain about.&lt;/p&gt;

&lt;p&gt;PHP excels when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need fast development&lt;/li&gt;
&lt;li&gt;You want predictable hosting&lt;/li&gt;
&lt;li&gt;You are building web-first applications&lt;/li&gt;
&lt;li&gt;You want a mature ecosystem&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How PHP Has Evolved
&lt;/h2&gt;

&lt;p&gt;One mistake people make is judging PHP based on how it worked ten years ago.&lt;/p&gt;

&lt;p&gt;Modern PHP includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strong typing options&lt;/li&gt;
&lt;li&gt;Improved performance&lt;/li&gt;
&lt;li&gt;Better memory handling&lt;/li&gt;
&lt;li&gt;Cleaner syntax&lt;/li&gt;
&lt;li&gt;Mature tooling and standards&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of modern PHP style:&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;UserRepository&lt;/span&gt; &lt;span class="nv"&gt;$repository&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;findActiveUsers&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;array&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;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getActive&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;This looks and behaves like modern backend code, not a scripting language from the past.&lt;/p&gt;

&lt;p&gt;PHP today is structured, readable, and scalable when written properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  PHP in Real Production Systems
&lt;/h2&gt;

&lt;p&gt;This is where the discussion usually ends.&lt;/p&gt;

&lt;p&gt;Large companies do not choose technologies based on trends. They choose what works.&lt;/p&gt;

&lt;p&gt;PHP is used in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large-scale e-commerce platforms&lt;/li&gt;
&lt;li&gt;High-traffic news websites&lt;/li&gt;
&lt;li&gt;Financial systems&lt;/li&gt;
&lt;li&gt;Internal enterprise tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If PHP was truly dying, companies would be migrating away from it in large numbers. That is not happening.&lt;/p&gt;

&lt;p&gt;Instead, many teams are modernizing PHP codebases rather than replacing them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Career Perspective for Developers
&lt;/h2&gt;

&lt;p&gt;From a career point of view, PHP is still a strong option in 2026.&lt;/p&gt;

&lt;p&gt;Why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There is consistent demand&lt;/li&gt;
&lt;li&gt;Many businesses already rely on PHP&lt;/li&gt;
&lt;li&gt;PHP developers are needed to maintain and improve existing systems&lt;/li&gt;
&lt;li&gt;Laravel skills translate well into backend architecture thinking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PHP may not always be the trendiest language, but it pays bills, builds products, and solves problems.&lt;/p&gt;

&lt;p&gt;For junior developers, PHP is also easier to enter compared to lower-level backend languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  When PHP Is a Bad Choice
&lt;/h2&gt;

&lt;p&gt;Being honest matters.&lt;/p&gt;

&lt;p&gt;PHP is not ideal when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need heavy real-time systems&lt;/li&gt;
&lt;li&gt;You are building game engines&lt;/li&gt;
&lt;li&gt;You require extremely low-level performance control&lt;/li&gt;
&lt;li&gt;Your team is already deeply invested in another ecosystem&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every language has limits. PHP is no exception.&lt;/p&gt;

&lt;p&gt;Choosing PHP should be a conscious decision, not an automatic one.&lt;/p&gt;

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

&lt;p&gt;PHP is not dying. It is not outdated. It is not irrelevant.&lt;/p&gt;

&lt;p&gt;PHP is stable, mature, and practical.&lt;/p&gt;

&lt;p&gt;In 2026, PHP continues to be valuable for developers who care about building real applications rather than chasing trends. The language has evolved, the ecosystem is strong, and the demand is steady.&lt;/p&gt;

&lt;p&gt;If you learn PHP properly and pair it with modern practices, you are not falling behind. You are building skills that still matter.&lt;/p&gt;

&lt;p&gt;The real question is not whether PHP is valuable.&lt;br&gt;
The real question is whether you are writing PHP the right way.&lt;/p&gt;

&lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/arafatweb" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/arafatweb&lt;/a&gt;&lt;br&gt;
Portfolio: &lt;a href="https://arafatdev.com/" rel="noopener noreferrer"&gt;https://arafatdev.com/&lt;/a&gt;&lt;br&gt;
GitHub: &lt;a href="https://github.com/arafat-web" rel="noopener noreferrer"&gt;https://github.com/arafat-web&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>programming</category>
      <category>2026</category>
    </item>
    <item>
      <title>Top 10 VS Code Extensions for PHP Developers in 2026</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Sun, 25 Jan 2026 06:28:22 +0000</pubDate>
      <link>https://forem.com/arafatweb/top-10-vs-code-extensions-for-php-developers-in-2026-199m</link>
      <guid>https://forem.com/arafatweb/top-10-vs-code-extensions-for-php-developers-in-2026-199m</guid>
      <description>&lt;p&gt;PHP remains a core language for backend development, powering applications from small websites to large enterprise systems. Visual Studio Code has become the editor of choice for many PHP developers because of its speed, flexibility, and strong extension ecosystem.&lt;/p&gt;

&lt;p&gt;When I first started using VS Code for PHP, choosing the right extensions was confusing. There were dozens of options, many overlapping, and some already outdated. Over time, I narrowed things down to a small set of extensions that genuinely improve productivity, reduce bugs, and make PHP development smoother.&lt;/p&gt;

&lt;p&gt;In this blog, I’ll walk through the &lt;strong&gt;top 10 VS Code extensions for PHP developers in 2026&lt;/strong&gt;, explain why they matter, and how they help in real-world projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;PHP Intelephense&lt;/li&gt;
&lt;li&gt;PHP CS Fixer&lt;/li&gt;
&lt;li&gt;PHP Debug (Xdebug)&lt;/li&gt;
&lt;li&gt;Laravel (Official)&lt;/li&gt;
&lt;li&gt;Blade Snippets&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;GitLens&lt;/li&gt;
&lt;li&gt;Code Runner&lt;/li&gt;
&lt;li&gt;EditorConfig for VS Code&lt;/li&gt;
&lt;li&gt;Thunder Client&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PHP Intelephense is still the foundation of PHP development in VS Code. It provides intelligent autocompletion, type inference, error detection, and navigation across large codebases.&lt;/p&gt;

&lt;p&gt;In real projects, it helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Catch undefined variables before runtime&lt;/li&gt;
&lt;li&gt;Jump between classes and methods instantly&lt;/li&gt;
&lt;li&gt;Understand function signatures without opening documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For most developers, VS Code without Intelephense does not feel complete.&lt;/p&gt;

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

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code consistency becomes critical as projects grow and teams expand. PHP CS Fixer automatically formats your code based on standards like PSR-12.&lt;/p&gt;

&lt;p&gt;Example configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"php-cs-fixer.enable"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"php-cs-fixer.enableAutoFixOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This removes formatting arguments from code reviews and keeps the entire codebase consistent.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. PHP Debug (Xdebug)
&lt;/h2&gt;

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Debugging with &lt;code&gt;dd()&lt;/code&gt; and logs only gets you so far. PHP Debug integrates Xdebug directly into VS Code, allowing you to set breakpoints and inspect variables while the code runs.&lt;/p&gt;

&lt;p&gt;Typical usage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debug complex request flows&lt;/li&gt;
&lt;li&gt;Understand why a condition behaves unexpectedly&lt;/li&gt;
&lt;li&gt;Step through framework internals when needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you get comfortable with Xdebug, debugging becomes far less stressful.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Laravel (Official)
&lt;/h2&gt;

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=laravel.vscode-laravel" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=laravel.vscode-laravel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a major change compared to previous years. Laravel now maintains an &lt;strong&gt;official VS Code extension&lt;/strong&gt; that replaces multiple community extensions.&lt;/p&gt;

&lt;p&gt;It provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Route autocompletion&lt;/li&gt;
&lt;li&gt;Blade syntax support&lt;/li&gt;
&lt;li&gt;Laravel helper and facade suggestions&lt;/li&gt;
&lt;li&gt;Artisan command integration&lt;/li&gt;
&lt;li&gt;Improved Laravel project awareness&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Laravel developers in 2026, this single extension covers what used to require several separate tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Blade Snippets
&lt;/h2&gt;

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even with the official Laravel extension, Blade Snippets remains useful for faster template writing.&lt;/p&gt;

&lt;p&gt;It helps by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Expanding Blade directives quickly&lt;/li&gt;
&lt;li&gt;Reducing repetitive typing&lt;/li&gt;
&lt;li&gt;Keeping view files clean and readable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It pairs well with the official Laravel extension.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Docker
&lt;/h2&gt;

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most modern PHP applications now run inside containers. The Docker extension allows you to manage containers directly from VS Code.&lt;/p&gt;

&lt;p&gt;With it, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start and stop services&lt;/li&gt;
&lt;li&gt;Inspect container logs&lt;/li&gt;
&lt;li&gt;Attach debuggers to running containers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This keeps your workflow inside the editor instead of jumping between terminals and tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. GitLens
&lt;/h2&gt;

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitLens enhances the built-in Git features of VS Code and is invaluable in team environments.&lt;/p&gt;

&lt;p&gt;It helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;See who last modified a line&lt;/li&gt;
&lt;li&gt;Explore commit history per file&lt;/li&gt;
&lt;li&gt;Understand why changes were made&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This context is extremely useful during debugging and code reviews.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Code Runner
&lt;/h2&gt;

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code Runner is useful for quick experiments and testing small PHP scripts.&lt;/p&gt;

&lt;p&gt;Example:&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="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Quick test"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can run this instantly without configuring a full project or server, which is great for learning and prototyping.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. EditorConfig for VS Code
&lt;/h2&gt;

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;EditorConfig ensures consistent coding styles across different editors and operating systems.&lt;/p&gt;

&lt;p&gt;It controls:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Indentation&lt;/li&gt;
&lt;li&gt;Line endings&lt;/li&gt;
&lt;li&gt;File encoding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This becomes especially important when multiple developers work on the same project.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Thunder Client
&lt;/h2&gt;

&lt;p&gt;Link: &lt;a href="https://marketplace.visualstudio.com/items?itemName=rangav.vscode-thunder-client" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=rangav.vscode-thunder-client&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thunder Client is a modern replacement for older REST tools inside VS Code.&lt;/p&gt;

&lt;p&gt;It allows you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test APIs&lt;/li&gt;
&lt;li&gt;Send HTTP requests&lt;/li&gt;
&lt;li&gt;Save collections per project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For backend PHP developers working with APIs, this removes the need for external tools.&lt;/p&gt;

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

&lt;p&gt;In 2026, PHP development in VS Code is more useful than ever. Many older extensions are no longer needed, and official tooling has replaced fragmented solutions, especially in the Laravel ecosystem.&lt;/p&gt;

&lt;p&gt;By choosing a focused and up-to-date extension set, you reduce noise, avoid conflicts, and build a development environment that actually supports how modern PHP applications are built today.&lt;/p&gt;

&lt;p&gt;Start with the essentials, add what you truly need, and keep your editor lean. That alone can noticeably improve both productivity and code quality.&lt;/p&gt;

&lt;p&gt;What are your go-to VS Code extensions for php development? Share your recommendations in the comments below!&lt;/p&gt;

&lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/arafatweb" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/arafatweb&lt;/a&gt;&lt;br&gt;
Portfolio: &lt;a href="https://arafatdev.com/" rel="noopener noreferrer"&gt;https://arafatdev.com/&lt;/a&gt;&lt;br&gt;
GitHub: &lt;a href="https://github.com/arafat-web" rel="noopener noreferrer"&gt;https://github.com/arafat-web&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>vscode</category>
      <category>php</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Pusher vs Socket.io Explained for Beginners</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Tue, 13 Jan 2026 10:06:14 +0000</pubDate>
      <link>https://forem.com/arafatweb/pusher-vs-socketio-explained-for-beginners-5d0p</link>
      <guid>https://forem.com/arafatweb/pusher-vs-socketio-explained-for-beginners-5d0p</guid>
      <description>&lt;p&gt;You have probably heard people say things like “just use WebSockets” or “Pusher is easier” when talking about real time features. At first, this topic usually feels confusing, boring, or overly technical, especially if you are still getting comfortable with backend development. In this post, I will break down Pusher vs Socket.io using simple language and real-world examples so you can clearly understand what each one does and when to use them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What problem are we trying to solve&lt;/li&gt;
&lt;li&gt;What is Pusher&lt;/li&gt;
&lt;li&gt;What is Socket.io&lt;/li&gt;
&lt;li&gt;A simple real-world analogy&lt;/li&gt;
&lt;li&gt;Setup and development experience&lt;/li&gt;
&lt;li&gt;Control and flexibility&lt;/li&gt;
&lt;li&gt;Scaling and infrastructure&lt;/li&gt;
&lt;li&gt;Code examples side by side&lt;/li&gt;
&lt;li&gt;Common mistakes beginners make&lt;/li&gt;
&lt;li&gt;When should you choose which&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What problem are we trying to solve
&lt;/h2&gt;

&lt;p&gt;Both Pusher and Socket.io exist to solve the same core problem.&lt;/p&gt;

&lt;p&gt;How do you send data from the server to the browser instantly without the browser asking for it every few seconds?&lt;/p&gt;

&lt;p&gt;Examples of this problem include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chat messages appearing instantly&lt;/li&gt;
&lt;li&gt;Notifications updating in real time&lt;/li&gt;
&lt;li&gt;Live dashboards&lt;/li&gt;
&lt;li&gt;Online collaboration features&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without WebSockets or similar tools, you would rely on polling, which is inefficient and slow.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Pusher
&lt;/h2&gt;

&lt;p&gt;Pusher is a hosted real time messaging service.&lt;/p&gt;

&lt;p&gt;You do not run WebSocket servers yourself. Pusher gives you an API and infrastructure that handles connections, scaling, and message delivery.&lt;/p&gt;

&lt;p&gt;You mainly focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sending events from your backend&lt;/li&gt;
&lt;li&gt;Listening for events on the frontend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You do not worry much about servers, load balancing, or connection management.&lt;/p&gt;

&lt;p&gt;Key characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Managed service&lt;/li&gt;
&lt;li&gt;Very fast to set up&lt;/li&gt;
&lt;li&gt;Paid after a small free tier&lt;/li&gt;
&lt;li&gt;Less control over low-level behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Socket.io
&lt;/h2&gt;

&lt;p&gt;Socket. IO is a JavaScript library that helps you build real time applications using WebSockets.&lt;/p&gt;

&lt;p&gt;Unlike Pusher, you host and manage the server yourself.&lt;/p&gt;

&lt;p&gt;You are responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Running the WebSocket server&lt;/li&gt;
&lt;li&gt;Scaling it&lt;/li&gt;
&lt;li&gt;Handling reconnects and edge cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open source&lt;/li&gt;
&lt;li&gt;Full control&lt;/li&gt;
&lt;li&gt;No service cost, but infrastructure cost&lt;/li&gt;
&lt;li&gt;More setup and maintenance&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A simple real-world analogy
&lt;/h2&gt;

&lt;p&gt;Think of a restaurant.&lt;/p&gt;

&lt;p&gt;Using Pusher is like hiring a food delivery service.&lt;/p&gt;

&lt;p&gt;You prepare the food and hand it over, and the delivery company takes care of drivers, routes, and timing. You pay for the service, but your workload is smaller.&lt;/p&gt;

&lt;p&gt;Using Socket.io is like running your own delivery fleet.&lt;/p&gt;

&lt;p&gt;You hire drivers, manage vehicles, plan routes, and deal with breakdowns. You have full control but also full responsibility.&lt;/p&gt;

&lt;p&gt;Neither approach is wrong. They serve different needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup and development experience
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pusher setup
&lt;/h3&gt;

&lt;p&gt;Pusher setup is usually quick.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an account&lt;/li&gt;
&lt;li&gt;Get app keys&lt;/li&gt;
&lt;li&gt;Install a backend SDK&lt;/li&gt;
&lt;li&gt;Install a frontend SDK&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can often send your first real time event in under an hour.&lt;/p&gt;

&lt;p&gt;This is especially friendly for beginners or small teams.&lt;/p&gt;

&lt;h3&gt;
  
  
  Socket.io setup
&lt;/h3&gt;

&lt;p&gt;Socket.io requires more steps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Node.js server&lt;/li&gt;
&lt;li&gt;Configure Socket.io&lt;/li&gt;
&lt;li&gt;Manage connections&lt;/li&gt;
&lt;li&gt;Think about scaling early&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not bad, but it is more work, especially if your main backend is PHP or Laravel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Control and flexibility
&lt;/h2&gt;

&lt;p&gt;This is where Socket.io shines.&lt;/p&gt;

&lt;p&gt;With Socket.io, you control:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication logic&lt;/li&gt;
&lt;li&gt;Custom events&lt;/li&gt;
&lt;li&gt;Room management&lt;/li&gt;
&lt;li&gt;Message routing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With Pusher, you work within their system.&lt;/p&gt;

&lt;p&gt;You trade flexibility for simplicity.&lt;/p&gt;

&lt;p&gt;If you need deep customization, Socket.io usually wins.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scaling and infrastructure
&lt;/h2&gt;

&lt;p&gt;Scaling is the biggest difference.&lt;/p&gt;

&lt;p&gt;Pusher handles scaling for you. If traffic spikes, your app usually keeps working.&lt;/p&gt;

&lt;p&gt;With Socket.io, scaling means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple servers&lt;/li&gt;
&lt;li&gt;Shared state&lt;/li&gt;
&lt;li&gt;Redis or similar tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is doable, but not beginner-friendly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code examples side by side
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Sending an event with Pusher in PHP
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$pusher&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'chat-channel'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'new-message'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'user'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Hello world'&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this does:&lt;br&gt;
It sends a real time event called &lt;code&gt;new-message&lt;/code&gt; to everyone listening on &lt;code&gt;chat-channel&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Why it matters:&lt;br&gt;
You do not manage connections yourself.&lt;/p&gt;

&lt;p&gt;When to use it:&lt;br&gt;
Simple real time features with minimal setup.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sending a message with Socket.io
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;connection&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;send-message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;new-message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&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;What this does:&lt;br&gt;
It listens for a message and broadcasts it to all connected clients.&lt;/p&gt;

&lt;p&gt;Why it matters:&lt;br&gt;
You fully control how messages flow.&lt;/p&gt;

&lt;p&gt;When to use it:&lt;br&gt;
Complex real time systems that need customization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes beginners make
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Choosing Socket.io without understanding scaling&lt;/li&gt;
&lt;li&gt;Using Pusher for extremely custom workflows&lt;/li&gt;
&lt;li&gt;Mixing real-time tools without a clear plan&lt;/li&gt;
&lt;li&gt;Ignoring security and authentication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start simple. Complexity can always be added later.&lt;/p&gt;

&lt;h2&gt;
  
  
  When should you choose which
&lt;/h2&gt;

&lt;p&gt;Choose Pusher if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want speed and simplicity&lt;/li&gt;
&lt;li&gt;You are new to real-time systems&lt;/li&gt;
&lt;li&gt;You do not want to manage infrastructure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose Socket.io if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need full control&lt;/li&gt;
&lt;li&gt;You are comfortable managing servers&lt;/li&gt;
&lt;li&gt;You expect complex real-time logic&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Most beginners think the choice is about which tool is better. In reality, it is about responsibility.&lt;/p&gt;

&lt;p&gt;Pushers remove responsibility in exchange for cost and limits. Socket.io gives you power in exchange for maintenance and complexity.&lt;/p&gt;

&lt;p&gt;If you are still learning backend development, starting with Pusher is often a calmer and safer path. Once you understand real-time concepts well, Socket.io starts to make a lot more sense.&lt;/p&gt;

&lt;p&gt;Take the path that reduces friction for your current stage, not the one that sounds more impressive.&lt;/p&gt;

</description>
      <category>socket</category>
      <category>backend</category>
      <category>pusher</category>
      <category>realtime</category>
    </item>
    <item>
      <title>Understanding the Laravel Lifecycle (Explained for Beginners)</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Sun, 05 Oct 2025 07:21:21 +0000</pubDate>
      <link>https://forem.com/arafatweb/understanding-the-laravel-lifecycle-explained-for-beginners-dc6</link>
      <guid>https://forem.com/arafatweb/understanding-the-laravel-lifecycle-explained-for-beginners-dc6</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Laravel Lifecycle&lt;/strong&gt; is one of the most asked interview questions for junior developers and for good reason.&lt;/p&gt;

&lt;p&gt;At first, it may sound complex, but once you understand how it works, you’ll find it surprisingly elegant and even exciting.&lt;/p&gt;

&lt;p&gt;Let’s break it down in simple words and real-world examples.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Table of Contents&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What Is the Laravel Lifecycle?&lt;/li&gt;
&lt;li&gt;Step-by-Step Breakdown&lt;/li&gt;
&lt;li&gt;Real-World Analogy&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;1. What Is the Laravel Lifecycle?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In short, the &lt;strong&gt;Laravel Lifecycle&lt;/strong&gt; is the full journey of a user’s request from the moment it enters your application until the response is sent back to the browser.&lt;/p&gt;

&lt;p&gt;Think of it like ordering food at a restaurant:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You (the user) make a &lt;strong&gt;request&lt;/strong&gt; (place an order).&lt;/li&gt;
&lt;li&gt;The kitchen (Laravel) processes your order.&lt;/li&gt;
&lt;li&gt;You get your &lt;strong&gt;response&lt;/strong&gt; (the dish served).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s exactly what Laravel does it receives a request, processes it through multiple layers, and returns a response.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;2. Step-by-Step Breakdown&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s go through each step that happens behind the scenes when you load a Laravel page.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: The Entry Point – &lt;code&gt;public/index.php&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Every request starts at &lt;strong&gt;&lt;code&gt;public/index.php&lt;/code&gt;&lt;/strong&gt;, which is Laravel’s &lt;strong&gt;entry point&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It’s like the &lt;strong&gt;main gate&lt;/strong&gt; of a building no matter where you come from, everyone enters through it.&lt;/p&gt;

&lt;p&gt;From here, Laravel starts bootstrapping (preparing) the application.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: The Bootstrap Process – &lt;code&gt;bootstrap/app.php&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After entering &lt;code&gt;index.php&lt;/code&gt;, the request moves to &lt;strong&gt;&lt;code&gt;bootstrap/app.php&lt;/code&gt;&lt;/strong&gt;, where Laravel’s &lt;strong&gt;Application Instance&lt;/strong&gt; is created.&lt;/p&gt;

&lt;p&gt;You can think of this as Laravel “waking up” it sets up everything it needs to handle the request.&lt;/p&gt;

&lt;p&gt;At this point, Laravel loads the &lt;strong&gt;Kernel&lt;/strong&gt;, which acts like the “traffic manager” of the application.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Service Providers Load&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, Laravel loads all &lt;strong&gt;Service Providers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These are the &lt;strong&gt;core building blocks&lt;/strong&gt; that boot up features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database connections&lt;/li&gt;
&lt;li&gt;Event handling&lt;/li&gt;
&lt;li&gt;Routing&lt;/li&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s like a car starting its systems the engine, AC, lights, and brakes all come online before you start driving.&lt;/p&gt;

&lt;p&gt;You can find all service providers in &lt;code&gt;config/app.php&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Middleware Runs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before the request reaches your controller, Laravel passes it through &lt;strong&gt;Middleware&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Middleware are like &lt;strong&gt;security gates&lt;/strong&gt; they check and filter requests.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Checking if the user is logged in (&lt;code&gt;Auth&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Protecting against CSRF attacks&lt;/li&gt;
&lt;li&gt;Managing sessions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any middleware fails (e.g., user not logged in), Laravel stops the request right there and returns a proper response (like redirecting to a login page).&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Routing and Controllers&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once the request passes through middleware, &lt;strong&gt;Laravel’s routing system&lt;/strong&gt; decides &lt;strong&gt;where to send it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/user/profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;UserController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'show'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Laravel checks if the route &lt;code&gt;/user/profile&lt;/code&gt; exists.&lt;/li&gt;
&lt;li&gt;It finds that it should call the &lt;code&gt;show()&lt;/code&gt; method of &lt;code&gt;UserController&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Laravel executes that controller method.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can think of the route as a &lt;strong&gt;GPS&lt;/strong&gt; that directs your request to the correct location.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 6: Models, Database, and Response&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Inside the controller, Laravel may use &lt;strong&gt;Models&lt;/strong&gt; to interact with the &lt;strong&gt;Database&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example:&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="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;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;return&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;'profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what happens behind the scenes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The controller asks the Model (&lt;code&gt;User&lt;/code&gt;) to fetch data from the database.&lt;/li&gt;
&lt;li&gt;The database returns the result.&lt;/li&gt;
&lt;li&gt;The controller sends that data to a &lt;strong&gt;view file&lt;/strong&gt; (Blade template).&lt;/li&gt;
&lt;li&gt;Laravel converts the view into an &lt;strong&gt;HTML response&lt;/strong&gt; and sends it back to the browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In short:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Controller → Model → Database → Controller → View → Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;3. Real-World Analogy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Imagine Laravel as a &lt;strong&gt;restaurant&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Laravel Component&lt;/th&gt;
&lt;th&gt;Restaurant Equivalent&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;code&gt;index.php&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Main entrance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;code&gt;app.php&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Kitchen setup&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Service Providers&lt;/td&gt;
&lt;td&gt;Staff preparing tools&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Middleware&lt;/td&gt;
&lt;td&gt;Security checking tickets&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Routing&lt;/td&gt;
&lt;td&gt;Waiter taking your order to the right chef&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Controller &amp;amp; Model&lt;/td&gt;
&lt;td&gt;Chef preparing the meal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Response&lt;/td&gt;
&lt;td&gt;Meal served to your table&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;By the time your meal (response) reaches you, Laravel has handled dozens of internal tasks but it all happens in milliseconds!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;4. Final Thoughts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The Laravel Lifecycle might look complex at first, but once you understand the flow, it becomes one of the most fascinating parts of the framework.&lt;/p&gt;

&lt;p&gt;Understanding this process helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debug your application more effectively.&lt;/li&gt;
&lt;li&gt;Write optimized and organized code.&lt;/li&gt;
&lt;li&gt;Appreciate how Laravel handles so much for you behind the scenes.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Quick Recap of the Flow&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Entry (index.php)
→ bootstrap/app.php
→ Kernel
→ Service Providers
→ Middleware
→ Routing
→ Controller
→ Model
→ Database
→ Controller
→ View/Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Laravel makes this entire process feel seamless transforming a simple user request into a powerful, structured response in just a fraction of a second.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>architecture</category>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Top 10 VS Code Extensions for Laravel Developers in 2025</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Mon, 29 Sep 2025 13:20:13 +0000</pubDate>
      <link>https://forem.com/arafatweb/top-10-vs-code-extensions-for-laravel-developers-in-2025-1np5</link>
      <guid>https://forem.com/arafatweb/top-10-vs-code-extensions-for-laravel-developers-in-2025-1np5</guid>
      <description>&lt;p&gt;Hey everyone,&lt;/p&gt;

&lt;p&gt;Let's talk about our primary tool: the code editor. A fresh install of VS Code is great, but if you're serious about Laravel development, you're leaving a ton of productivity on the table without the right extensions. The right setup can automate the boring stuff, catch errors, and make your entire workflow feel smoother.&lt;/p&gt;

&lt;p&gt;After years of tweaking my own environment, I've narrowed it down to a core set of tools that I use on every single project. These are the extensions that genuinely make a difference in my day-to-day.&lt;/p&gt;

&lt;p&gt;Here is my definitive list of the 10 must-have VS Code extensions for any Laravel developer in 2025.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; Laravel - The Official Extension
&lt;/li&gt;
&lt;li&gt; Laravel Blade Snippets
&lt;/li&gt;
&lt;li&gt; Laravel Extra Intellisense
&lt;/li&gt;
&lt;li&gt; Laravel Goto View
&lt;/li&gt;
&lt;li&gt; PHP Intelephense
&lt;/li&gt;
&lt;li&gt; Laravel Pint
&lt;/li&gt;
&lt;li&gt; PHP Debug
&lt;/li&gt;
&lt;li&gt; REST Client
&lt;/li&gt;
&lt;li&gt; Prettier - Code Formatter
&lt;/li&gt;
&lt;li&gt;GitLens&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  1. Laravel - The Official Extension
&lt;/h3&gt;

&lt;p&gt;This is the big one, often overlooked because it's so awesome. It includes everything from Artisan commands right in your command palette to route and view navigation, validation rules completion, and even environment variable management. It's truly an all-in-one powerhouse that streamlines so many daily tasks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; A comprehensive toolkit that brings many Laravel-specific functionalities directly into VS Code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=laravel.vscode-laravel" rel="noopener noreferrer"&gt;Laravel on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Laravel Blade Snippets
&lt;/h3&gt;

&lt;p&gt;Even with the main Laravel extension, this focused extension for Blade is incredibly valuable. It adds robust syntax highlighting and a massive collection of snippets for Blade directives, conditionals, and loops. Typing &lt;code&gt;b:foreach&lt;/code&gt; and hitting tab to get the full structure for a loop is a small thing that saves a ton of time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Drastically speeds up the creation and editing of your Blade templates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade" rel="noopener noreferrer"&gt;Laravel Blade Snippets on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Laravel Extra Intellisense
&lt;/h3&gt;

&lt;p&gt;This is your go-to for making VS Code truly understand your Laravel project's internal workings. It provides intelligent autocompletion for route names, views, config values, and even validation rules. No more guessing route names or constantly flipping between files. It just works.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Boosts coding speed and accuracy by providing smart, context-aware autocompletion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=amiralizadeh9480.laravel-extra-intellisense" rel="noopener noreferrer"&gt;Laravel Extra Intellisense on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Laravel Goto View
&lt;/h3&gt;

&lt;p&gt;Jumping between your controllers and their corresponding views can be a hassle. This extension makes it trivial. Simply &lt;code&gt;Ctrl+Click&lt;/code&gt; (or &lt;code&gt;Cmd+Click&lt;/code&gt; on Mac) on a view name in your controller, and you're instantly transported to that Blade file.&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="c1"&gt;// In your controller...&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;show&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="c1"&gt;// Ctrl+Clicking on 'posts.show' takes you directly to the view file.&lt;/span&gt;
    &lt;span class="k"&gt;return&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;'posts.show'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;compact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'post'&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;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Provides seamless navigation between your PHP logic and your Blade templates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=codingyu.laravel-goto-view" rel="noopener noreferrer"&gt;Laravel Goto View on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. PHP Intelephense
&lt;/h3&gt;

&lt;p&gt;While not Laravel-specific, this is the absolute foundation for any PHP development in VS Code. It offers incredibly fast code completion, signature help, go-to-definition, and detailed diagnostics. It's the engine that powers most of the "smart" features you expect from an IDE for PHP code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Transforms VS Code into a robust, high-performance PHP IDE.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client" rel="noopener noreferrer"&gt;PHP Intelephense on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. Laravel Pint
&lt;/h3&gt;

&lt;p&gt;Code consistency is key for maintainable projects and smooth team collaboration. Laravel Pint is the official, zero-configuration PHP code style fixer. This extension integrates Pint directly into VS Code, automatically formatting your PHP files on save according to Laravel's coding standards.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Automates code formatting, ensuring a clean and consistent style across your PHP codebase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=open-southeners.laravel-pint" rel="noopener noreferrer"&gt;Laravel Pint on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  7. PHP Debug
&lt;/h3&gt;

&lt;p&gt;Stop relying solely on &lt;code&gt;dd()&lt;/code&gt; for debugging. Learning to use a proper step-debugger is a huge leap in productivity. This extension integrates Xdebug, allowing you to set breakpoints, inspect variables, and step through your code line-by-line. It's invaluable for tracking down complex bugs efficiently.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Provides professional-grade debugging capabilities directly within your editor.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug" rel="noopener noreferrer"&gt;PHP Debug on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. REST Client
&lt;/h3&gt;

&lt;p&gt;Many Laravel projects involve building and consuming APIs. This extension allows you to send HTTP requests and view the responses directly within VS Code, eliminating the need to switch to external tools like Postman for quick testing. You define your requests in a &lt;code&gt;.http&lt;/code&gt; file with a straightforward syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;### Get all users from the API
GET http://my-app.test/api/users
Accept: application/json
Authorization: Bearer YOUR_API_TOKEN

###
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Streamlines API testing by keeping it within your development environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=humao.rest-client" rel="noopener noreferrer"&gt;REST Client on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9. Prettier - Code Formatter
&lt;/h3&gt;

&lt;p&gt;While Laravel Pint keeps your PHP tidy, Prettier handles everything else. It's an opinionated code formatter for JavaScript, CSS, JSON, Markdown, and more. It ensures a consistent and clean style across all your front-end assets, making your entire project visually cohesive.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Ensures consistent code formatting across all non-PHP files in your project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode" rel="noopener noreferrer"&gt;Prettier - Code Formatter&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  10. GitLens
&lt;/h3&gt;

&lt;p&gt;This extension significantly enhances VS Code's built-in Git capabilities. GitLens provides invaluable features like inline blame annotations (showing who changed what line and when), a powerful history view, and easy comparison tools. It's crucial for understanding codebase evolution and collaborating effectively.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why it's essential:&lt;/strong&gt; Offers deep insights into your Git repository history directly within your editor.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grab it here:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens" rel="noopener noreferrer"&gt;GitLens on Marketplace&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  FAQs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Q: Do I need to install all of these?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Not necessarily. This is a comprehensive list, but you should prioritize extensions that address your biggest pain points. Start with the main "Laravel" extension and PHP Intelephense, then add others as needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q: Are these extensions free?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Yes, all extensions mentioned are free to use. Some might offer premium tiers for advanced features, but their free versions provide substantial benefits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q: Will these extensions slow down my VS Code?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; While having many extensions &lt;em&gt;can&lt;/em&gt; theoretically impact performance, those listed here are generally well-optimized. VS Code also includes tools to monitor extension performance. It's good practice to disable any extensions you don't actively use.&lt;/p&gt;




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

&lt;p&gt;Equipping your VS Code with the right extensions is one of the quickest ways to boost your productivity as a Laravel developer. By using these tools, you can streamline common tasks, ensure code quality, and make your development experience much more efficient and enjoyable.&lt;/p&gt;

&lt;p&gt;What are your go-to VS Code extensions for Laravel development? Share your recommendations in the comments below!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LinkedIn:&lt;/strong&gt; &lt;a href="https://www.google.com/search?q=https://www.linkedin.com/in/arafatweb" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/arafatweb&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portfolio:&lt;/strong&gt; &lt;a href="https://arafatdev.com/" rel="noopener noreferrer"&gt;https://arafatdev.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/arafat-web" rel="noopener noreferrer"&gt;https://github.com/arafat-web&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>laravel</category>
      <category>vscode</category>
      <category>php</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Bulk Email Sender v2.0: From Simple Tool to Professional Email Marketing Platform</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Sat, 26 Jul 2025 08:33:34 +0000</pubDate>
      <link>https://forem.com/arafatweb/bulk-email-sender-v20-from-simple-tool-to-professional-email-marketing-platform-29dm</link>
      <guid>https://forem.com/arafatweb/bulk-email-sender-v20-from-simple-tool-to-professional-email-marketing-platform-29dm</guid>
      <description>&lt;p&gt;Hey dev community! 👋 &lt;/p&gt;

&lt;p&gt;Remember that bulk email sender I built with Laravel a while back? Well, it's gotten a MASSIVE upgrade! What started as a simple tool for sending bulk emails has evolved into a full-fledged email marketing platform. Let me walk you through everything that's new in v2.0!&lt;/p&gt;

&lt;h2&gt;
  
  
  What Was Missing in v1.0?
&lt;/h2&gt;

&lt;p&gt;Don't get me wrong - v1.0 did its job. You could send bulk emails, and that was pretty much it. But after using it for a while (and getting feedback from the community), I realized it was missing some crucial features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No proper contact management&lt;/li&gt;
&lt;li&gt;Couldn't send individual emails&lt;/li&gt;
&lt;li&gt;No way to organize contacts&lt;/li&gt;
&lt;li&gt;Basic UI that looked... well, basic&lt;/li&gt;
&lt;li&gt;No proper queue system for large campaigns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sound familiar? Yeah, I know. It was more of a "quick hack" than a professional tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's New in v2.0? (Spoiler: A LOT!)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Complete Contact Management System
&lt;/h3&gt;

&lt;p&gt;This was the big one! Now you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add contacts individually or in bulk&lt;/li&gt;
&lt;li&gt;Import from CSV/Excel files (with proper validation!)&lt;/li&gt;
&lt;li&gt;View all contacts in a clean, paginated table&lt;/li&gt;
&lt;li&gt;Edit and delete contacts easily&lt;/li&gt;
&lt;li&gt;Export your contact lists&lt;/li&gt;
&lt;/ul&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%2Fvyt9exn63yjhooz8u7a7.png" 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%2Fvyt9exn63yjhooz8u7a7.png" alt="Contact Management" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Smart Tag System
&lt;/h3&gt;

&lt;p&gt;Want to send emails to just your VIP customers? Or maybe only to people from a specific city? Tags got you covered!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create custom tags (VIP, City-NYC, Newsletter-Subscribers, etc.)&lt;/li&gt;
&lt;li&gt;Assign multiple tags to contacts&lt;/li&gt;
&lt;li&gt;Send targeted campaigns to specific tags&lt;/li&gt;
&lt;li&gt;Filter contacts by tags&lt;/li&gt;
&lt;/ul&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%2Fqltzgbmd1gzwnyf2lnw8.png" 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%2Fqltzgbmd1gzwnyf2lnw8.png" alt="Tag Management" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Individual Email Feature
&lt;/h3&gt;

&lt;p&gt;Sometimes you don't want to send to everyone. Now you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Send personalized emails to specific contacts&lt;/li&gt;
&lt;li&gt;Use the same rich text editor&lt;/li&gt;
&lt;li&gt;Perfect for follow-ups or personal messages&lt;/li&gt;
&lt;/ul&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%2Fk7i9p0aul07lx454z6wr.png" 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%2Fk7i9p0aul07lx454z6wr.png" alt="Individual Emails" width="800" height="1010"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Modern UI Overhaul
&lt;/h3&gt;

&lt;p&gt;Let's be honest - v1.0 looked like it was built in 2010. v2.0 brings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clean, modern Bootstrap 5 design&lt;/li&gt;
&lt;li&gt;Responsive layout that works on mobile&lt;/li&gt;
&lt;li&gt;Proper navigation with breadcrumbs&lt;/li&gt;
&lt;li&gt;Dark mode support (because why not?)&lt;/li&gt;
&lt;li&gt;Professional sidebar navigation&lt;/li&gt;
&lt;/ul&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%2F1uaxhlnnocmk54mgy4dv.png" 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%2F1uaxhlnnocmk54mgy4dv.png" alt="Dashboard" width="800" height="1155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Excel Import/Export
&lt;/h3&gt;

&lt;p&gt;This one was a game-changer for productivity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import contacts from CSV/Excel files&lt;/li&gt;
&lt;li&gt;Proper validation and error handling&lt;/li&gt;
&lt;li&gt;Export your contacts for backup&lt;/li&gt;
&lt;li&gt;Sample CSV template provided&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. 🔧 Queue System Integration
&lt;/h3&gt;

&lt;p&gt;No more waiting around for large campaigns! Now using Laravel Queues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Background email processing&lt;/li&gt;
&lt;li&gt;No timeouts on large campaigns&lt;/li&gt;
&lt;li&gt;Better server resource management&lt;/li&gt;
&lt;li&gt;Real-time progress tracking&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Technical Improvements
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Code Quality
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Proper MVC architecture&lt;/li&gt;
&lt;li&gt;Form validation with Laravel's built-in validators&lt;/li&gt;
&lt;li&gt;Database relationships and migrations&lt;/li&gt;
&lt;li&gt;Queue jobs for email processing&lt;/li&gt;
&lt;li&gt;Error handling and logging&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Performance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Paginated contact lists&lt;/li&gt;
&lt;li&gt;Optimized database queries&lt;/li&gt;
&lt;li&gt;Asset optimization with Vite&lt;/li&gt;
&lt;li&gt;Proper caching strategies&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Security
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;CSRF protection on all forms&lt;/li&gt;
&lt;li&gt;Input sanitization&lt;/li&gt;
&lt;li&gt;SQL injection prevention&lt;/li&gt;
&lt;li&gt;Secure file uploads&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation &amp;amp; Setup (It's Still Super Easy!)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Clone the repository&lt;/span&gt;
git clone https://github.com/arafat-web/Bulk-Email-Sender.git
&lt;span class="nb"&gt;cd &lt;/span&gt;Bulk-Email-Sender

&lt;span class="c"&gt;# Install dependencies&lt;/span&gt;
composer &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Setup environment&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; .env.example .env
php artisan key:generate

&lt;span class="c"&gt;# Setup database&lt;/span&gt;
php artisan migrate &lt;span class="nt"&gt;--seed&lt;/span&gt;

&lt;span class="c"&gt;# Start the application&lt;/span&gt;
php artisan serve
php artisan queue:work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Default login:&lt;/strong&gt; &lt;code&gt;admin@email.com&lt;/code&gt; / &lt;code&gt;12345678&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Use Cases
&lt;/h2&gt;

&lt;p&gt;Since launching v2.0, I've seen people use it for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Newsletter Management&lt;/strong&gt; - Import subscribers, organize by interests with tags&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Invitations&lt;/strong&gt; - Send bulk invites, then individual follow-ups&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customer Support&lt;/strong&gt; - Organize customers by product, send targeted updates&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Marketing Campaigns&lt;/strong&gt; - Segment audiences with tags, track engagement&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community Management&lt;/strong&gt; - Organize members, send announcements&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What I Learned Building This
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. User Feedback is Gold
&lt;/h3&gt;

&lt;p&gt;The v1.0 feedback taught me that users needed more than just "send email to everyone." They needed organization, targeting, and flexibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. UI/UX Matters More Than I Thought
&lt;/h3&gt;

&lt;p&gt;A clean interface isn't just pretty - it actually makes the tool more efficient to use. Who knew? 😅&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Laravel Queues Are Amazing
&lt;/h3&gt;

&lt;p&gt;Seriously, if you're not using queues for heavy tasks, you're missing out. Game-changer for user experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Progressive Enhancement Works
&lt;/h3&gt;

&lt;p&gt;Started simple with v1.0, then added features based on actual needs. Much better than trying to build everything upfront.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;I'm already thinking about v3.0! Some ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Email templates management&lt;/li&gt;
&lt;li&gt;A/B testing for campaigns&lt;/li&gt;
&lt;li&gt;Analytics and reporting&lt;/li&gt;
&lt;li&gt;API for integrations&lt;/li&gt;
&lt;li&gt;Multi-user support&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Want to Contribute?
&lt;/h2&gt;

&lt;p&gt;The project is completely open source! Whether you want to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Report bugs&lt;/li&gt;
&lt;li&gt;Suggest features&lt;/li&gt;
&lt;li&gt;Submit pull requests&lt;/li&gt;
&lt;li&gt;Improve documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything is welcome! Check out the &lt;a href="https://github.com/arafat-web/Bulk-Email-Sender" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Screenshots Gallery
&lt;/h2&gt;

&lt;p&gt;Here are some more screenshots showing the features in action:&lt;/p&gt;

&lt;h3&gt;
  
  
  Email Templates
&lt;/h3&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%2F40la7agarxc85naxdxgj.png" 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%2F40la7agarxc85naxdxgj.png" alt="Email Templates" width="800" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Instant Campaign
&lt;/h3&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%2Fy1b2tsjt7ujbf5xhomt5.png" 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%2Fy1b2tsjt7ujbf5xhomt5.png" alt="Instant Campaign" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Email Accounts Settings
&lt;/h3&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%2Fd3j8jch558vqgwkq2iuu.png" 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%2Fd3j8jch558vqgwkq2iuu.png" alt="Email Accounts" width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Building v2.0 has been an incredible journey. What started as a simple weekend project has become something I'm genuinely proud of. The Laravel community's feedback and support made this possible.&lt;/p&gt;

&lt;p&gt;If you're working on email marketing, managing newsletters, or just need to send bulk emails occasionally, give it a try! And if you find it useful, a ⭐ on GitHub would make my day!&lt;/p&gt;

&lt;h2&gt;
  
  
  🔗 Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/arafat-web/Bulk-Email-Sender" rel="noopener noreferrer"&gt;arafat-web/Bulk-Email-Sender&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live Demo&lt;/strong&gt;: &lt;a href="https://arafat-web.github.io/Bulk-Email-Sender/" rel="noopener noreferrer"&gt;GitHub Pages&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;My Website&lt;/strong&gt;: &lt;a href="https://arafatdev.com" rel="noopener noreferrer"&gt;arafatdev.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;What do you think about v2.0? Have you built similar tools? I'd love to hear your thoughts and experiences in the comments below! 👇&lt;/em&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>opensource</category>
      <category>marketing</category>
    </item>
    <item>
      <title>Design Your Database with dbdiagram.io (Beginner to Pro)</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Thu, 26 Jun 2025 14:29:43 +0000</pubDate>
      <link>https://forem.com/arafatweb/design-your-database-with-dbdiagramio-beginner-to-pro-20j6</link>
      <guid>https://forem.com/arafatweb/design-your-database-with-dbdiagramio-beginner-to-pro-20j6</guid>
      <description>&lt;p&gt;Designing a database schema can either be a quick sketch or a total nightmare, especially if you're working on a big project or collaborating with a team. But what if you could &lt;strong&gt;visually plan, share, and even generate your database schema&lt;/strong&gt; with just a few lines of easy-to-write code?&lt;/p&gt;

&lt;p&gt;That’s exactly what &lt;strong&gt;&lt;a href="https://dbdiagram.io" rel="noopener noreferrer"&gt;dbdiagram.io&lt;/a&gt;&lt;/strong&gt; helps you do. Whether you're a backend developer, a full-stack dev, or a database enthusiast, this tool will &lt;strong&gt;make your life 10x easier&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is dbdiagram.io?&lt;/li&gt;
&lt;li&gt;Why Use dbdiagram.io?&lt;/li&gt;
&lt;li&gt;Supported Syntax &amp;amp; Importing From Tools&lt;/li&gt;
&lt;li&gt;Let’s Design a Real Example – Blog System Schema&lt;/li&gt;
&lt;li&gt;Exporting SQL Scripts&lt;/li&gt;
&lt;li&gt;Collaboration &amp;amp; Sharing&lt;/li&gt;
&lt;li&gt;Tips for Better Schema Design&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  What is dbdiagram.io?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;dbdiagram.io&lt;/strong&gt; is a free, online database design tool where you can create database diagrams using a simple DSL (domain-specific language) or by importing your schema directly.&lt;/p&gt;

&lt;p&gt;No need to install clunky software or memorize ER diagram notations — just focus on &lt;strong&gt;what your data should look like&lt;/strong&gt;, and the tool takes care of the visualization.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Use dbdiagram.io?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Easy to use&lt;/strong&gt;: Just write schema like you're writing a config file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast prototyping&lt;/strong&gt;: Great for startups, side-projects, or freelance gigs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visually shareable&lt;/strong&gt;: Auto-generates ER diagrams that you can share via links.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Supports real DBs&lt;/strong&gt;: PostgreSQL, MySQL, SQL Server, Oracle, and more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Free for individuals and small teams&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Supported Syntax &amp;amp; Importing From Tools
&lt;/h3&gt;

&lt;p&gt;You can use either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;dbml (Database Markup Language)&lt;/strong&gt; – dbdiagram’s native, super readable DSL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL (MySQL/PostgreSQL)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Import from tools&lt;/strong&gt; like MySQL Workbench, PostgreSQL, Prisma, or Rails.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Let’s Design a Real Example – Blog System Schema
&lt;/h3&gt;

&lt;p&gt;Here's a real-world example of designing a database schema for a blogging platform using &lt;strong&gt;dbml&lt;/strong&gt; syntax.&lt;/p&gt;

&lt;h4&gt;
  
  
  ER Diagram DSL
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Table users {
  id int [pk, increment]
  name varchar
  email varchar
  password varchar
  created_at datetime
  updated_at datetime
}

Table profiles {
  id int [pk, increment]
  user_id int [ref: &amp;gt; users.id]
  bio text
  avatar_url varchar
  created_at datetime
  updated_at datetime
}

Table posts {
  id int [pk, increment]
  user_id int [ref: &amp;gt; users.id]
  title varchar
  content text
  created_at datetime
  updated_at datetime
}

Table comments {
  id int [pk, increment]
  post_id int [ref: &amp;gt; posts.id]
  user_id int [ref: &amp;gt; users.id]
  content text
  created_at datetime
  updated_at datetime
}

Table categories {
  id int [pk, increment]
  name varchar
  created_at datetime
  updated_at datetime
}

Table post_categories {
  post_id int [ref: &amp;gt; posts.id]
  category_id int [ref: &amp;gt; categories.id]
  created_at datetime
  updated_at datetime
  Note: 'Composite Primary Key'
  indexes {
    (post_id, category_id) [pk]
  }
}

Table tags {
  id int [pk, increment]
  name varchar
  created_at datetime
  updated_at datetime
}

Table post_tags {
  post_id int [ref: &amp;gt; posts.id]
  tag_id int [ref: &amp;gt; tags.id]
  created_at datetime
  updated_at datetime
  Note: 'Composite Primary Key'
  indexes {
    (post_id, tag_id) [pk]
  }
}

Table likes {
  id int [pk, increment]
  post_id int [ref: &amp;gt; posts.id]
  user_id int [ref: &amp;gt; users.id]
  created_at datetime
  updated_at datetime
  indexes {
    (post_id, user_id) [unique]
  }
}

Table followers {
  follower_id int [ref: &amp;gt; users.id]
  following_id int [ref: &amp;gt; users.id]
  created_at datetime
  Note: 'User following relationship'
  indexes {
    (follower_id, following_id) [pk]
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste this into &lt;a href="https://dbdiagram.io/d" rel="noopener noreferrer"&gt;https://dbdiagram.io/d&lt;/a&gt;, and you’ll instantly see a fully functional, visual representation of a blogging platform’s database (below image). No clicking, dragging, or aligning just clean, readable code.&lt;/p&gt;

&lt;h2&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%2F2bsm5jbgfwsefp7zdky7.png" alt="blog dbdiagram" width="800" height="745"&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Exporting SQL Scripts
&lt;/h3&gt;

&lt;p&gt;Once your schema is complete, dbdiagram can generate the equivalent SQL for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;PostgreSQL&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MySQL&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL Server&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQLite&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just hit &lt;code&gt;Export &amp;gt; SQL&lt;/code&gt; and you’re ready to run it in your database setup.&lt;/p&gt;




&lt;h3&gt;
  
  
  Collaboration &amp;amp; Sharing
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Version control friendly&lt;/strong&gt; – Save your dbml code in &lt;code&gt;.dbml&lt;/code&gt; files in GitHub&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Share via link&lt;/strong&gt; – Collaborators can view your schema without signing up&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Teams&lt;/strong&gt; – Upgrade to a team plan to collaborate in real-time&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Tips for Better Schema Design
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Always use &lt;code&gt;id&lt;/code&gt; as primary key unless you &lt;strong&gt;really&lt;/strong&gt; need composite keys.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;created_at&lt;/code&gt; and &lt;code&gt;updated_at&lt;/code&gt; fields for better tracking.&lt;/li&gt;
&lt;li&gt;Use foreign keys to define relationships instead of managing them manually.&lt;/li&gt;
&lt;li&gt;Normalize, but don’t over-normalize. Balance is key.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;ENUM&lt;/code&gt; or &lt;code&gt;lookup tables&lt;/code&gt; for things like post status, user roles, etc.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Whether you're a solo developer working on your next SaaS idea, or part of a big team managing microservices, &lt;strong&gt;dbdiagram.io is a game-changer&lt;/strong&gt; for designing and communicating your database architecture.&lt;/p&gt;

&lt;p&gt;It saves you from visual mess, enforces good structure, and helps your team stay aligned, all without needing to open MySQL Workbench.&lt;/p&gt;




&lt;h4&gt;
  
  
  Useful Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Try it here: &lt;a href="https://dbdiagram.io" rel="noopener noreferrer"&gt;dbdiagram.io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Full documentation: &lt;a href="https://dbdocs.io/docs" rel="noopener noreferrer"&gt;dbdocs.io/docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub-friendly DBML: &lt;a href="https://github.com/holistics/dbml" rel="noopener noreferrer"&gt;https://github.com/holistics/dbml&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you loved this breakdown, let me know! Want me to cover more visual dev tools like this? Drop a comment.&lt;/p&gt;

</description>
      <category>database</category>
      <category>mysql</category>
      <category>sql</category>
      <category>postgres</category>
    </item>
    <item>
      <title>🚀 10 Laravel Eloquent Tricks You Didn’t Know (But Will Love!)</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Mon, 21 Apr 2025 15:06:04 +0000</pubDate>
      <link>https://forem.com/arafatweb/10-laravel-eloquent-tricks-you-didnt-know-but-will-love-505c</link>
      <guid>https://forem.com/arafatweb/10-laravel-eloquent-tricks-you-didnt-know-but-will-love-505c</guid>
      <description>&lt;p&gt;Laravel’s Eloquent ORM is one of the most powerful tools in the PHP ecosystem. But let’s be honest, most developers stick to &lt;code&gt;get()&lt;/code&gt;, &lt;code&gt;where()&lt;/code&gt;, and &lt;code&gt;find()&lt;/code&gt;. Eloquent actually has many hidden features that can help you write cleaner, faster, and more maintainable code.&lt;/p&gt;

&lt;p&gt;In this blog, you’ll discover 10 lesser-known Eloquent methods and techniques that will level up your Laravel skills.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
withWhereHas() – Filter and Eager Load in One Query
&lt;/li&gt;
&lt;li&gt;
cursorPaginate() – Paginate Large Datasets Efficiently
&lt;/li&gt;
&lt;li&gt;
sole() – Ensure Only One Record Exists
&lt;/li&gt;
&lt;li&gt;
upsert() – Insert or Update Multiple Rows at Once
&lt;/li&gt;
&lt;li&gt;
lazy() – Loop Through Big Data Without Memory Issues
&lt;/li&gt;
&lt;li&gt;
findMany() – Fetch Multiple Records Easily
&lt;/li&gt;
&lt;li&gt;
whereBelongsTo() – Query Using a Model Instance
&lt;/li&gt;
&lt;li&gt;
is() – Compare Models Safely
&lt;/li&gt;
&lt;li&gt;
firstOrCreate() and updateOrCreate() – Atomic Record Handling
&lt;/li&gt;
&lt;li&gt;tap() – Inspect Queries in the Middle of a Chain&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. withWhereHas() – Filter and Eager Load in One Query
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;withWhereHas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'comments'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'approved'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&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;get&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoids multiple queries&lt;/li&gt;
&lt;li&gt;Reduces memory usage&lt;/li&gt;
&lt;li&gt;Keeps your code concise&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. cursorPaginate() – Paginate Large Datasets Efficiently
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$users&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;orderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&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;cursorPaginate&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Great for infinite scroll or continuous loading&lt;/li&gt;
&lt;li&gt;Handles large datasets without slowing down&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. sole() – Ensure Only One Record Exists
&lt;/h3&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;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'admin@example.com'&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;sole&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eliminates silent bugs&lt;/li&gt;
&lt;li&gt;Ensures data uniqueness and consistency&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. upsert() – Insert or Update Multiple Rows at Once
&lt;/h3&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;upsert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'one@test.com'&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;'User One'&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;'two@test.com'&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;'User Two'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// Unique column&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;   &lt;span class="c1"&gt;// Columns to update&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prevents duplicates&lt;/li&gt;
&lt;li&gt;Minimizes database load&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. lazy() – Loop Through Big Data Without Memory Issues
&lt;/h3&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;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'active'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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;lazy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Process user&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keeps memory usage low&lt;/li&gt;
&lt;li&gt;Perfect for batch jobs, exports, and reporting&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. findMany() – Fetch Multiple Records Easily
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$users&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;findMany&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cleaner syntax&lt;/li&gt;
&lt;li&gt;More efficient than multiple queries&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  7. whereBelongsTo() – Query Using a Model Instance
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;whereBelongsTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&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;get&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More readable and expressive&lt;/li&gt;
&lt;li&gt;Helps when working directly with models&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. is() – Compare Models Safely
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&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;author&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$currentUser&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Perform action&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Safer than manual comparisons&lt;/li&gt;
&lt;li&gt;Works with unsaved models too&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9. firstOrCreate() and updateOrCreate() – Atomic Record Handling
&lt;/h3&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;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;'someone@example.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;'Someone New'&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoids duplicate records&lt;/li&gt;
&lt;li&gt;Clean and readable&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  10. tap() – Inspect Queries in the Middle of a Chain
&lt;/h3&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;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'active'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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;tap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;toSql&lt;/span&gt;&lt;span class="p"&gt;());&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;get&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;Why it’s useful:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Great for debugging&lt;/li&gt;
&lt;li&gt;Keeps the method chain intact&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Laravel Eloquent is packed with powerful features that go beyond the basics. By using these lesser-known methods, you can write code that is not only more efficient but also easier to maintain and scale.&lt;/p&gt;

&lt;p&gt;Whether you're building APIs, admin panels, or full-blown applications, these tips will give your Laravel skills an extra edge.&lt;/p&gt;

&lt;h3&gt;
  
  
  Useful Links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://laravel.com/docs/eloquent" rel="noopener noreferrer"&gt;Official Eloquent Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/arafatweb"&gt;More Laravel Tips on Dev.to&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/arafat-web" rel="noopener noreferrer"&gt;Follow Me on GitHub&lt;/a&gt; for Laravel projects and tutorials&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Building a PHP CRUD Application with OOP and MySQL: A Best Practice Guide</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Fri, 10 Jan 2025 15:58:16 +0000</pubDate>
      <link>https://forem.com/arafatweb/building-a-php-crud-application-with-oop-and-mysql-a-best-practice-guide-19p</link>
      <guid>https://forem.com/arafatweb/building-a-php-crud-application-with-oop-and-mysql-a-best-practice-guide-19p</guid>
      <description>&lt;p&gt;When developing PHP applications, managing database operations effectively is crucial. One of the most common operations you’ll perform is CRUD (Create, Read, Update, Delete). Adopting Object-Oriented Programming (OOP) principles helps make your code cleaner, reusable, and scalable. Using MySQL with PHP also ensures that your application can handle data storage efficiently.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll go through building a &lt;strong&gt;PHP CRUD application&lt;/strong&gt; with &lt;strong&gt;OOP&lt;/strong&gt; and &lt;strong&gt;MySQL&lt;/strong&gt;. We’ll organize the code using best practices and design patterns that are beginner-friendly yet robust enough for larger projects.&lt;/p&gt;

&lt;p&gt;By the end of this guide, you will have a solid foundation for working with databases using OOP principles in PHP.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The Importance of OOP in PHP&lt;/li&gt;
&lt;li&gt;Setting Up the Project&lt;/li&gt;
&lt;li&gt;Creating the Database&lt;/li&gt;
&lt;li&gt;Folder Structure&lt;/li&gt;
&lt;li&gt;Connecting to the Database&lt;/li&gt;
&lt;li&gt;
Creating CRUD Operations

&lt;ul&gt;
&lt;li&gt;Create&lt;/li&gt;
&lt;li&gt;Read&lt;/li&gt;
&lt;li&gt;Update&lt;/li&gt;
&lt;li&gt;Delete&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. The Importance of OOP in PHP
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Object-Oriented Programming (OOP)&lt;/strong&gt; is a programming paradigm that uses "objects" to organize code. In PHP, OOP allows you to create classes that represent real-world entities, making your code more modular, reusable, and easier to manage.&lt;/p&gt;

&lt;p&gt;When working with databases, applying OOP principles means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Separation of Concerns&lt;/strong&gt;: Database logic is encapsulated in a class, separate from the rest of your application logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reusability&lt;/strong&gt;: You can reuse the database class in multiple parts of the application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainability&lt;/strong&gt;: Your code is easier to update and extend as your application grows.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Setting Up the Project
&lt;/h3&gt;

&lt;p&gt;Before diving into coding, let’s set up a folder structure that’s easy to maintain. Here’s how your project should be organized:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php-crud/
├── config/
│   └── Database.php
├── controllers/
│   └── UserController.php
├── models/
│   └── User.php
├── views/
│   └── user_list.php
├── public/
│   └── index.php
└── .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;config/Database.php&lt;/strong&gt;: Contains the database connection logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;controllers/UserController.php&lt;/strong&gt;: Handles CRUD operations and communicates with the model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;models/User.php&lt;/strong&gt;: Contains the logic to interact with the &lt;code&gt;users&lt;/code&gt; table in MySQL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;views/user_list.php&lt;/strong&gt;: Displays user data in a table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;public/index.php&lt;/strong&gt;: The entry point for the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Creating the Database
&lt;/h3&gt;

&lt;p&gt;Let’s start by creating the database and a &lt;code&gt;users&lt;/code&gt; table in MySQL. You can execute the following SQL queries to set up the database:&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;DATABASE&lt;/span&gt; &lt;span class="n"&gt;php_crud&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;USE&lt;/span&gt; &lt;span class="n"&gt;php_crud&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="n"&gt;AUTO_INCREMENT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&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;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;email&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;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="nb"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;CURRENT_TIMESTAMP&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This table will store basic user information such as &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;email&lt;/code&gt;, and &lt;code&gt;created_at&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Folder Structure
&lt;/h3&gt;

&lt;p&gt;We’ve already set up the basic folder structure. Here’s a breakdown of each folder’s purpose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;config/&lt;/strong&gt;: Contains the database configuration and connection logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;controllers/&lt;/strong&gt;: Handles requests and calls the appropriate methods from the model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;models/&lt;/strong&gt;: Represents the business logic and database interactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;views/&lt;/strong&gt;: Displays the data to the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;public/&lt;/strong&gt;: The public folder contains the &lt;code&gt;index.php&lt;/code&gt; file, which will be the entry point for the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Connecting to the Database
&lt;/h3&gt;

&lt;p&gt;Let’s start by creating a database connection class in &lt;code&gt;config/Database.php&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="no"&gt;PDO&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;Database&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'127.0.0.1'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$dbName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'php_crud'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'root'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$connection&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;connect&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PDO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s2"&gt;"mysql:host=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;dbname=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;dbName&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;
            &lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ATTR_ERRMODE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ERRMODE_EXCEPTION&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;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;die&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Database connection failed: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class creates a PDO connection to MySQL and is reusable across your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Creating CRUD Operations
&lt;/h3&gt;

&lt;p&gt;Let’s create a model for handling user data. This class will interact with the &lt;code&gt;users&lt;/code&gt; table and perform CRUD operations.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Create Model (User.php)&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Models&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;Config\Database&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;User&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$conn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$database&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"INSERT INTO users (name, email) VALUES (:name, :email)"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;bindParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;bindParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$email&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;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"SELECT * FROM users"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;execute&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;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fetchAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;\PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;FETCH_ASSOC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"UPDATE users SET name = :name, email = :email WHERE id = :id"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;bindParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;bindParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;bindParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$id&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;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"DELETE FROM users WHERE id = :id"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;bindParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$id&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;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;execute&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;h4&gt;
  
  
  &lt;strong&gt;Create Controller (UserController.php)&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Controllers&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;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;UserController&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;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="p"&gt;)&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;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&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="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;()&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;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&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="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;updateUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="p"&gt;)&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;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&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="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;deleteUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&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;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&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="nb"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$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;h4&gt;
  
  
  &lt;strong&gt;Create View (user_list.php)&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c1"&gt;// This file is responsible for displaying the list of users.&lt;/span&gt;

&lt;span class="k"&gt;require_once&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../controllers/UserController.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$userController&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;\Controllers\UserController&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nv"&gt;$users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$userController&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;h1&amp;gt;User List&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;table&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;ID&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Email&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Actions&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$users&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;a href='update.php?id=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;'&amp;gt;Edit&amp;lt;/a&amp;gt; | &amp;lt;a href='delete.php?id=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;'&amp;gt;Delete&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;/table&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Create the Entry Point (index.php)&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;require_once&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../models/User.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;require_once&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../controllers/UserController.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$userController&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;\Controllers\UserController&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Example: Create a user&lt;/span&gt;
&lt;span class="nv"&gt;$userController&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&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;'john@example.com'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Example: Read users&lt;/span&gt;
&lt;span class="nv"&gt;$userController&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;By following OOP principles and applying best practices in PHP, we’ve built a simple and scalable CRUD application. This approach makes it easy to expand your project with new features or improve database interactions.&lt;/p&gt;

&lt;p&gt;In this guide, we’ve covered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A simple and maintainable folder structure.&lt;/li&gt;
&lt;li&gt;A reusable &lt;code&gt;Database&lt;/code&gt; class for MySQL connections.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;User&lt;/code&gt; model that encapsulates all CRUD operations.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;UserController&lt;/code&gt; to handle business logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This structure makes your PHP applications cleaner, more modular, and easier to extend. You can now take this approach and build larger, more complex applications using OOP and MySQL.&lt;/p&gt;

&lt;p&gt;Happy coding! 🎉&lt;/p&gt;

</description>
      <category>php</category>
      <category>oop</category>
      <category>sql</category>
      <category>mysql</category>
    </item>
    <item>
      <title>Unit Testing in Laravel: A Practical Approach for Developers</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Wed, 20 Nov 2024 19:08:12 +0000</pubDate>
      <link>https://forem.com/arafatweb/unit-testing-in-laravel-a-practical-approach-for-developers-7oa</link>
      <guid>https://forem.com/arafatweb/unit-testing-in-laravel-a-practical-approach-for-developers-7oa</guid>
      <description>&lt;p&gt;Testing is a critical part of software development, but it often feels like a chore. Fortunately, Laravel makes testing a breeze with its built-in tools, helping developers ensure their applications work as expected without spending endless hours debugging. Whether you’re building a small project or a large-scale application, unit testing can save you from potential headaches by catching issues early.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll explore &lt;strong&gt;unit testing in Laravel&lt;/strong&gt;—what it is, why it’s important, and how to get started with writing tests. By the end, you’ll understand how to create and execute tests in Laravel with real-world examples.&lt;/p&gt;




&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is Unit Testing?&lt;/li&gt;
&lt;li&gt;Why Unit Testing is Important&lt;/li&gt;
&lt;li&gt;Setting Up Unit Testing in Laravel&lt;/li&gt;
&lt;li&gt;Writing Your First Unit Test&lt;/li&gt;
&lt;li&gt;Testing Models, Controllers, and Services&lt;/li&gt;
&lt;li&gt;Running and Interpreting Tests&lt;/li&gt;
&lt;li&gt;Best Practices for Laravel Unit Testing&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  What is Unit Testing?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Unit testing&lt;/strong&gt; is a type of testing where you write code to test individual units of your application, like functions, methods, or classes. These tests are small, fast, and focus on ensuring a specific piece of code works as expected. &lt;/p&gt;

&lt;p&gt;In Laravel, unit tests are typically written using &lt;strong&gt;PHPUnit&lt;/strong&gt;, which comes pre-installed with Laravel.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Unit Testing is Important
&lt;/h3&gt;

&lt;p&gt;Unit testing might feel like extra work at first, but the benefits far outweigh the initial effort. Here’s why it’s worth your time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Catch Bugs Early&lt;/strong&gt;: Tests help identify bugs before your application goes live, saving you from costly fixes later.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Refactor with Confidence&lt;/strong&gt;: Knowing your tests will catch any issues makes refactoring safer and more efficient.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improve Code Quality&lt;/strong&gt;: Writing tests forces you to think through your code’s logic and edge cases, leading to cleaner, more robust code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ensure Consistency&lt;/strong&gt;: Tests ensure that updates or new features don’t break existing functionality.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Setting Up Unit Testing in Laravel
&lt;/h3&gt;

&lt;p&gt;Laravel is pre-configured for unit testing, so you don’t need to install any additional tools. Here’s how to get started:&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Check PHPUnit Installation
&lt;/h4&gt;

&lt;p&gt;Laravel includes PHPUnit out of the box. You can check the version by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/phpunit &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Create a Test Class
&lt;/h4&gt;

&lt;p&gt;Laravel provides a handy Artisan command to generate a new test class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:test ExampleTest &lt;span class="nt"&gt;--unit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a test file in the &lt;code&gt;tests/Unit&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tests/
├── Unit/
│   └── ExampleTest.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Configure the Testing Environment
&lt;/h4&gt;

&lt;p&gt;Laravel uses the &lt;code&gt;.env.testing&lt;/code&gt; file for testing. Copy your &lt;code&gt;.env&lt;/code&gt; file and rename it to &lt;code&gt;.env.testing&lt;/code&gt;. Update the database configuration to use a separate testing database, ensuring your tests don’t affect your development database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_CONNECTION=sqlite
DB_DATABASE=:memory:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Writing Your First Unit Test
&lt;/h3&gt;

&lt;p&gt;Let’s write a simple test to check if a method in a class returns the expected value.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: Testing a Math Helper Function
&lt;/h4&gt;

&lt;p&gt;Create a helper class in &lt;code&gt;app/Helpers/MathHelper.php&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="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Helpers&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;MathHelper&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;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$b&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;$a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;$b&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;Write a test for this function in &lt;code&gt;tests/Unit/MathHelperTest.php&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="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Tests\Unit&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;PHPUnit\Framework\TestCase&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\Helpers\MathHelper&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;MathHelperTest&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;TestCase&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;testAddition&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MathHelper&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;assertEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$result&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;Run the test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/phpunit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is correct, PHPUnit will output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OK (1 test, 1 assertion)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Testing Models, Controllers, and Services
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Testing Models
&lt;/h4&gt;

&lt;p&gt;Models are central to any Laravel application. Let’s test a simple model method.&lt;/p&gt;

&lt;p&gt;Add a &lt;code&gt;User&lt;/code&gt; model with a custom method in &lt;code&gt;app/Models/User.php&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="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Models&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Database\Eloquent\Factories\HasFactory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Database\Eloquent\Model&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;User&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&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;HasFactory&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;isAdmin&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;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;role&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'admin'&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;Write a test in &lt;code&gt;tests/Unit/UserTest.php&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="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Tests\Unit&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;PHPUnit\Framework\TestCase&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;UserTest&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;TestCase&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;testIsAdmin&lt;/span&gt;&lt;span class="p"&gt;()&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;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&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;role&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'admin'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;assertTrue&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;isAdmin&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;h4&gt;
  
  
  Testing Controllers
&lt;/h4&gt;

&lt;p&gt;For controllers, you’ll typically use &lt;strong&gt;feature tests&lt;/strong&gt;, but you can still test individual methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  Testing Services
&lt;/h4&gt;

&lt;p&gt;Create a service in &lt;code&gt;app/Services/ExampleService.php&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="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Services&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;ExampleService&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;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&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="s2"&gt;"Hello, &lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt;!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write a test for it:&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;Tests\Unit&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;PHPUnit\Framework\TestCase&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\Services\ExampleService&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;ExampleServiceTest&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;TestCase&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;testGreeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ExampleService&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;assertEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hello, John!'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$service&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'John'&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;h3&gt;
  
  
  Running and Interpreting Tests
&lt;/h3&gt;

&lt;p&gt;To run all tests in your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/phpunit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run a specific test file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/phpunit tests/Unit/ExampleTest.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will show:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tests that passed.&lt;/li&gt;
&lt;li&gt;Tests that failed (with details on what went wrong).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Best Practices for Laravel Unit Testing
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Test Small Units&lt;/strong&gt;: Focus on small, isolated units of code, like a single method or function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Assertions Wisely&lt;/strong&gt;: Laravel provides many assertion methods, such as &lt;code&gt;assertEquals&lt;/code&gt;, &lt;code&gt;assertTrue&lt;/code&gt;, and &lt;code&gt;assertCount&lt;/code&gt;. Use them to verify expected outcomes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mock External Dependencies&lt;/strong&gt;: Use Laravel’s mocking capabilities to simulate database queries or API calls, ensuring tests are independent of external factors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run Tests Regularly&lt;/strong&gt;: Integrate testing into your development workflow to catch issues early.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Unit testing in Laravel doesn’t have to be intimidating. With its built-in tools and seamless integration with PHPUnit, Laravel makes it easy to write and manage tests. By adopting a testing-first mindset, you’ll ensure your application is robust, reliable, and ready for production.&lt;/p&gt;

&lt;p&gt;Start small—write a test for a single function or class. As you get comfortable, you’ll see how unit testing can transform your development process. Happy coding!&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>unittest</category>
      <category>web</category>
    </item>
    <item>
      <title>Machine Learning in PHP: Build a News Classifier Using Rubix ML</title>
      <dc:creator>Arafat Hossain Ar</dc:creator>
      <pubDate>Fri, 01 Nov 2024 16:51:39 +0000</pubDate>
      <link>https://forem.com/arafatweb/machine-learning-in-php-build-a-news-classifier-using-rubix-ml-e45</link>
      <guid>https://forem.com/arafatweb/machine-learning-in-php-build-a-news-classifier-using-rubix-ml-e45</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Machine learning is everywhere—recommending movies, tagging images, and now even classifying news articles. Imagine if you could do that within PHP! With &lt;a href="https://rubixml.com" rel="noopener noreferrer"&gt;&lt;strong&gt;Rubix ML&lt;/strong&gt;&lt;/a&gt;, you can bring the power of machine learning to PHP in a way that’s straightforward and accessible. This guide will walk you through building a simple &lt;strong&gt;news classifier&lt;/strong&gt; that sorts articles into categories like “Sports” or “Technology.” By the end, you’ll have a working classifier that can predict categories for new articles based on their content.&lt;/p&gt;

&lt;p&gt;This project is perfect for beginners who want to dip their toes into machine learning using PHP, and you can follow along with the complete code on &lt;a href="https://github.com/arafat-web/NewsClassifier" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is Rubix ML?&lt;/li&gt;
&lt;li&gt;Setting Up the Project&lt;/li&gt;
&lt;li&gt;Creating the News Classification Class&lt;/li&gt;
&lt;li&gt;Training the Model&lt;/li&gt;
&lt;li&gt;Predicting New Samples&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What is Rubix ML?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://rubixml.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Rubix ML&lt;/strong&gt;&lt;/a&gt; is a machine learning library for PHP that brings ML tools and algorithms into a PHP-friendly environment. Whether you’re working on classification, regression, clustering, or even natural language processing, Rubix ML has you covered. It allows you to load and preprocess data, train models, and evaluate performance—all in PHP.&lt;/p&gt;

&lt;p&gt;Rubix ML supports a wide range of machine learning tasks, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Classification&lt;/strong&gt;: Categorizing data, like labeling emails as spam or not spam.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regression&lt;/strong&gt;: Predicting continuous values, like housing prices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clustering&lt;/strong&gt;: Grouping data without labels, like finding customer segments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Natural Language Processing (NLP)&lt;/strong&gt;: Working with text data, such as tokenizing and transforming it into usable formats for ML.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s dive into how you can use Rubix ML to build a simple news classifier in PHP!&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up the Project
&lt;/h3&gt;

&lt;p&gt;We’ll start by setting up a new PHP project with Rubix ML and configuring autoloading.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Initialize the Project Directory
&lt;/h4&gt;

&lt;p&gt;Create a new project directory and navigate into it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;NewsClassifier
&lt;span class="nb"&gt;cd &lt;/span&gt;NewsClassifier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Install Rubix ML with Composer
&lt;/h4&gt;

&lt;p&gt;Make sure you have Composer installed, then add Rubix ML to your project by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require rubix/ml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Configure Autoloading in &lt;code&gt;composer.json&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;To autoload classes from our project’s &lt;code&gt;src&lt;/code&gt; directory, open or create a &lt;code&gt;composer.json&lt;/code&gt; file and add the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"autoload"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"psr-4"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"NewsClassifier\\"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src/"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"require"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"rubix/ml"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^2.5"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Composer to autoload any classes within the &lt;code&gt;src&lt;/code&gt; folder under the &lt;code&gt;NewsClassifier&lt;/code&gt; namespace.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4: Run Composer Autoload Dump
&lt;/h4&gt;

&lt;p&gt;After adding the autoload configuration, run the following command to regenerate Composer’s autoloader:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer dump-autoload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 5: Directory Structure
&lt;/h4&gt;

&lt;p&gt;Your project directory should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NewsClassifier/
├── src/
│   ├── Classification.php
│   └── train.php
├── storage/
├── vendor/
├── composer.json
└── composer.lock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;src/&lt;/strong&gt;: Contains your PHP scripts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;storage/&lt;/strong&gt;: Where the trained model will be saved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;vendor/&lt;/strong&gt;: Contains dependencies installed by Composer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Creating the News Classification Class
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;src/&lt;/code&gt;, create a file called &lt;code&gt;Classification.php&lt;/code&gt;. This file will contain the methods for training the model and predicting news categories.&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;NewsClassifier&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;Rubix\ML\Classifiers\KNearestNeighbors&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;Rubix\ML\Datasets\Labeled&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;Rubix\ML\Datasets\Unlabeled&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;Rubix\ML\PersistentModel&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;Rubix\ML\Pipeline&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;Rubix\ML\Tokenizers\Word&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;Rubix\ML\Transformers\TfIdfTransformer&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;Rubix\ML\Transformers\WordCountVectorizer&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;Rubix\ML\Persisters\Filesystem&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;Classification&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$modelPath&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Sample data and corresponding labels&lt;/span&gt;
        &lt;span class="nv"&gt;$samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'The team played an amazing game of soccer'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'The new programming language has been released'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'The match between the two teams was incredible'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'The new tech gadget has been launched'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="nv"&gt;$labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'sports'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'technology'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'sports'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'technology'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a labeled dataset&lt;/span&gt;
        &lt;span class="nv"&gt;$dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Labeled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$samples&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$labels&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Set up the pipeline with a text transformer and K-Nearest Neighbors classifier&lt;/span&gt;
        &lt;span class="nv"&gt;$estimator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pipeline&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WordCountVectorizer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Word&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TfIdfTransformer&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KNearestNeighbors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="c1"&gt;// Train the model&lt;/span&gt;
        &lt;span class="nv"&gt;$estimator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$dataset&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Save the model&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;saveModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$estimator&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Training completed and model saved.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;saveModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$estimator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$persister&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Filesystem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;modelPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PersistentModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$estimator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$persister&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$model&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;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;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$samples&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Load the saved model&lt;/span&gt;
        &lt;span class="nv"&gt;$persister&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Filesystem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;modelPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PersistentModel&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$persister&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Predict categories for new samples&lt;/span&gt;
        &lt;span class="nv"&gt;$dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Unlabeled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$samples&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;$model&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$dataset&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;This &lt;code&gt;Classification&lt;/code&gt; class contains methods to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Train&lt;/strong&gt;: Create and train a pipeline-based model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save the Model&lt;/strong&gt;: Save the trained model to the specified path.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Predict&lt;/strong&gt;: Load the saved model and predict the category for new samples.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Training the Model
&lt;/h3&gt;

&lt;p&gt;Create a script called &lt;code&gt;train.php&lt;/code&gt; in &lt;code&gt;src/&lt;/code&gt; to train the model.&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../vendor/autoload.php'&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;NewsClassifier\Classification&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define the model path&lt;/span&gt;
&lt;span class="nv"&gt;$modelPath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../storage/model.rbx'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Initialize the Classification object&lt;/span&gt;
&lt;span class="nv"&gt;$classifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Classification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$modelPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Train the model and save it&lt;/span&gt;
&lt;span class="nv"&gt;$classifier&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this script to train the model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php src/train.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If successful, you’ll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Training completed and model saved.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Predicting New Samples
&lt;/h3&gt;

&lt;p&gt;Create another script, &lt;code&gt;predict.php&lt;/code&gt;, in &lt;code&gt;src/&lt;/code&gt; to classify new articles based on the trained model.&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../vendor/autoload.php'&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;NewsClassifier\Classification&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define the path to the saved model&lt;/span&gt;
&lt;span class="nv"&gt;$modelPath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/../storage/model.rbx'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Initialize the Classification object&lt;/span&gt;
&lt;span class="nv"&gt;$classifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Classification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$modelPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Define new samples for classification&lt;/span&gt;
&lt;span class="nv"&gt;$samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'The team played an amazing game of soccer, showing excellent teamwork and strategy.'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'The latest programming language release introduces features that enhance coding efficiency.'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'An incredible match between two top teams ended in a thrilling draw last night.'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'This new tech gadget includes features never before seen, setting a new standard in the industry.'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Predict categories&lt;/span&gt;
&lt;span class="nv"&gt;$predictions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$classifier&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$samples&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Display predictions&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$predictions&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$index&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$prediction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Sample: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$samples&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$index&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="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Prediction: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$prediction&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&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;Run the prediction script to classify the samples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php src/predict.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output should show each sample text with its predicted category.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;With this guide, you’ve successfully built a simple news classifier in PHP using Rubix ML! This demonstrates how PHP can be more versatile than you might think, bringing in machine learning capabilities for tasks like text classification, recommendation systems, and more. The full code for this project is available on &lt;a href="https://github.com/arafat-web/NewsClassifier" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Experiment with different algorithms or data to expand the classifier. Who knew PHP could do machine learning? Now you do.&lt;br&gt;
Happy coding!&lt;/p&gt;

</description>
      <category>php</category>
      <category>machinelearning</category>
      <category>rubixml</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
