<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Codelite]]></title><description><![CDATA[Codelite]]></description><link>https://codelite.pro</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 17:20:32 GMT</lastBuildDate><atom:link href="https://codelite.pro/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA["Works on My Machine" Isn’t Defense: Fix Your Local PHP Environment]]></title><description><![CDATA[You’ve seen it a thousand times. Someone pushes code to production, a bug appears, and that message pings loudly

For some, it’s a joke. For most teams and senior developers, it’s a moment of frustration, mixed with dread.
The truth is simple: your l...]]></description><link>https://codelite.pro/works-on-my-machine-isnt-defense-fix-your-local-php-environment</link><guid isPermaLink="true">https://codelite.pro/works-on-my-machine-isnt-defense-fix-your-local-php-environment</guid><dc:creator><![CDATA[Samer Moustafa]]></dc:creator><pubDate>Thu, 08 Jan 2026 22:44:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1767907103115/3800306f-37bc-40f7-8ac4-5c37688cb2a4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You’ve seen it a thousand times. Someone pushes code to production, a bug appears, and that message pings loudly</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1767913077074/9e0628b2-972e-4c7c-a4a4-075a1fc3e4b2.avif" alt class="image--center mx-auto" /></p>
<p>For some, it’s a joke. For most teams and senior developers, it’s a moment of frustration, mixed with dread.</p>
<p>The truth is simple: your local environment is silently failing you. That green checkmark or status [200] on your laptop doesn’t guarantee that production will behave the same way. And this mismatch is one of the most common sources of wasted hours, heated debates, and stress in development teams.</p>
<p>This guide isn’t here to lecture you or tell you that you’re bad at your job. It’s here to help you understand why this keeps happening, and what you can do to prevent it, for your projects, your team, and your own sanity.</p>
<h2 id="heading-the-title-claim">The Title Claim</h2>
<p>The title of this guide isn’t provocative for no reason or SEO oriented. “Stop Blaming Production: Fix Your Local Environment” is a statement of principle, not accusation.</p>
<p>When a bug only shows up in production, it’s tempting to assume production is at fault. Maybe the server is misconfigured, maybe someone deployed the wrong code, maybe the database is weird. But in most cases, the environment you’re running locally is incomplete, inconsistent, or subtly different from production.</p>
<p>If you are seeking professionalism and aiming for seniority level then your professional mindset has to be :</p>
<blockquote>
<p>If you cannot reproduce a bug locally, you are debugging blind</p>
</blockquote>
<p>This is a core discipline. It’s not about blame, it’s about engineering integrity.</p>
<h2 id="heading-why-it-works-its-correct">Why “It Works” ≠ “It’s Correct”</h2>
<p>We’ve all been there. You follow a tutorial, install PHP, run a script, and it works. Mission accomplished.</p>
<p>But the problem is that “works” is a very limited signal. Most tutorials and quick-start guides are optimized for first success. They rarely cover edge cases, multi-version support, OS differences, or nuanced configuration.</p>
<p>So when you or your team stops at “it works,” what you’re really doing is hiding gaps. These gaps quietly accumulate until production exposes them as bugs that are hard to debug, inconsistent, or seemingly random.</p>
<p>This is the “works on my machine” trap: the environment gives a false sense of security.</p>
<h2 id="heading-the-real-reasons-bugs-dont-reproduce-locally">The Real Reasons Bugs Don’t Reproduce Locally</h2>
<p>Here’s what I see over and over in real-world teams and projects. Any one of these might be harmless, together, they’re a debugging <strong>nightmare</strong></p>
<p><strong>Runtime version mismatch</strong></p>
<p>You might be on PHP 8.3 locally, while production runs 8.2. Minor differences in behavior, deprecations, or extensions can cause subtle failures.</p>
<p><strong>Extensions and configuration differences</strong></p>
<p>Production might have opcache, gd, or intl enabled. Local setups may skip some of these, leading to inconsistent behavior.</p>
<p><strong>Environment drift</strong></p>
<p>Memory limits, max execution time, error reporting — these tiny differences shape what works and what breaks.</p>
<p><strong>Filesystem &amp; permissions differences</strong></p>
<p>Linux vs Windows line endings, user permissions, or ownership can silently block code that seems fine on a dev machine.</p>
<p><strong>Email, cache, or queue shortcuts</strong></p>
<p>Using Mailtrap everywhere feels safe, but it masks real SMTP or queue behavior. Cache or session shortcuts can hide race conditions.</p>
<p><strong>OS-level dependencies</strong></p>
<p>Missing libraries, system tools, or background services can make code fail in ways that only production exposes.</p>
<p><strong>Environment security level</strong></p>
<p>Production is usually more restricted, controlled and hand-configured, you default assumptions my been blocked there for a security reason</p>
<p>Individually, these feel minor. Together, they make debugging production a guessing game with blind eyes.</p>
<h2 id="heading-the-dangerous-mental-model">The Dangerous Mental Model</h2>
<p>Many developers unconsciously adopt this assumption : <strong>If it works locally, production must be wrong</strong>, this is a mental trap. It shifts responsibility away from professional engineering to finger-pointing.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1767913454738/436ea8c9-aac8-479d-b872-338693f63edc.png" alt class="image--center mx-auto" /></p>
<p>As developers we don’t point fingers, find the guilty one. Instead we find the cause, explain the scenario, introduce the fix and maintain stability and logically workflow.</p>
<p>The mature model flips this into :</p>
<blockquote>
<p>If it fails in production but not locally, my environment is incomplete</p>
</blockquote>
<p>This mindset shift is huge. It stops wasted arguments, hours of meetings, spams of email messages and sets the stage for systematic improvement.</p>
<h2 id="heading-local-production-but-it-must-be-comparable">Local ≠ Production (But It Must Be Comparable)</h2>
<p>Let’s be clear on this point: your local environment does not need to be an exact copy of production. Docker, VMs, Networking, Security level or configurations. Mirrors are great (in some cases), but overkill for most cases.</p>
<p>What matters is comparability:</p>
<ul>
<li><p><strong>PHP version alignment</strong> : same minor version at minimum</p>
</li>
<li><p><strong>Extensions that matter</strong> : match production for key behaviors</p>
</li>
<li><p><strong>Execution model</strong> : CLI vs FPM vs CGI differences</p>
</li>
<li><p><strong>Configuration assumptions</strong> : error reporting, memory limits, timezone</p>
</li>
<li><p><strong>Data and environment flow</strong> : caching, queues, and email delivery</p>
</li>
</ul>
<p>When these points match, you can reproduce bugs reliably and reduce fighting.</p>
<p><strong>Note</strong>: understanding the difference between how each OS / Kernel behaves is a must and adds a great bonus for your to spot the “cause” so early, but this is a large topic, so we will talk about this separately.</p>
<h2 id="heading-you-can-ignore-this-but-it-costs-much">You can ignore this .. but it costs much</h2>
<p>Ignoring environment drift is deceptively cheap, until it isn’t. Below is the real cost of ignoring</p>
<ul>
<li><p>Debugging becomes a guessing game</p>
</li>
<li><p>Logs are confusing or misleading</p>
</li>
<li><p>Simple upgrades feel risky</p>
</li>
<li><p>Developers avoid touching the environment</p>
</li>
<li><p>“Works on my machine” excuses multiply</p>
</li>
<li><p>Getting locked in “I don’t know why” zone</p>
</li>
</ul>
<p>Eventually, these small inefficiencies become team-wide pain. Every fight, every late-night patch, every long meeting, every subtle production bug is a symptom of local environments that aren’t trusted.</p>
<h2 id="heading-the-rule-keep-this-in-mind">The Rule — Keep this in mind</h2>
<p>Here is what i usually repeat almost daily and i keep remind myself as well :</p>
<blockquote>
<p>It’s not production’s fault. If you cannot reproduce it, you’re doing it wrong.</p>
</blockquote>
<p>Let’s unpack that carefully.</p>
<h3 id="heading-empathy-first">Empathy First</h3>
<p>You are not being blamed. You are not failing. If you’ve ever been stumped by a bug that disappears locally, you’ve been in this exact situation. That feeling of doubt is normal and universal.</p>
<h3 id="heading-a-career-saving-principle">A Career-Saving Principle</h3>
<p>This rule exists to protect your career. Reproducible environments save hours, reduce stress, and make you the developer others trust. Master this, and you’ll debug faster, upgrade versions confidently, and avoid wasting team time.</p>
<h3 id="heading-support-not-shame">Support, Not Shame</h3>
<p>This is guidance, not criticism. Applying this principle builds habits that protect your projects and your sanity. You’re creating <strong>predictable, maintainable local setups</strong>, and that’s a skill that separates good developers from great ones.</p>
<h3 id="heading-lens-for-evaluation">Lens for Evaluation</h3>
<p>Every pain point you’ve seen, version mismatches, permissions errors, email shortcuts can be seen through this lens. Ask yourself:</p>
<blockquote>
<p>If this bug were in production, could I reproduce it locally? If not, my environment needs improvement</p>
</blockquote>
<h3 id="heading-its-only-first-step">It’s only first step</h3>
<p>Reproducing a bug is only the first step. How you approach it, the questions you ask, the tools you choose, and the order in which you test hypotheses matters just as much. A reliable local environment gives you the canvas, but your thinking and debugging habits are the brush</p>
<p>It’s not about blame. It’s about building a reliable, professional career path.</p>
<h2 id="heading-practical-mini-framework-for-thinking">Practical Mini-Framework for Thinking</h2>
<p>When a bug only shows up in production, your <strong>mindset and debugging process</strong> matter as much as your environment. Here’s a simple mental checklist you can use every time:</p>
<ol>
<li><p><strong>Observe</strong> – Start by looking at logs, errors, and actual behavior. Don’t guess; gather evidence first.</p>
</li>
<li><p><strong>Hypothesize</strong> – Ask: <em>“What might be different between my local machine and production?”</em> Consider PHP version, extensions, OS differences, permissions, or service availability.</p>
</li>
<li><p><strong>Reproduce</strong> – Can you make the bug appear locally? If not, your environment or assumptions need adjustment.</p>
</li>
<li><p><strong>Test Tools</strong> – Check that your developer tools are showing accurate information. Are xdebug breakpoints working? Is your mail server setup reflecting real SMTP flows?</p>
</li>
<li><p><strong>Reflect</strong> – Finally, review your assumptions and shortcuts. Did you mask a symptom? Did a convenience tool hide the root cause?</p>
</li>
</ol>
<p>Following this simple framework turns “works on my machine” from an excuse into a repeatable debugging habit, giving you confidence and control over production issues.</p>
<h2 id="heading-what-a-correct-local-environment-optimizes-for">What a Correct Local Environment Optimizes For</h2>
<p>A proper local environment doesn’t just “work.” It is <strong>deliberately designed</strong> to:</p>
<ul>
<li><p><strong>Reproducibility</strong> → every bug can be reproduced</p>
</li>
<li><p><strong>Predictability</strong> → behavior matches production where it matters</p>
</li>
<li><p><strong>Version Awareness</strong> → multiple PHP versions handled safely</p>
</li>
<li><p><strong>Replaceability</strong> → easy to reset or rebuild</p>
</li>
<li><p><strong>Confidence</strong> → upgrades, tests, and experiments are safe</p>
</li>
</ul>
<p>When these are in place, “works on my machine” becomes <strong>irrelevant</strong>, because production behaves as expected.</p>
<h2 id="heading-responsibility-without-blame">Responsibility Without Blame</h2>
<p>This is a solvable problem.</p>
<p>A professional environment isn’t just about installing runtime or spinning up Docker. It’s about <strong>thinking like a senior engineer</strong>:</p>
<ul>
<li><p>Evaluate assumptions</p>
</li>
<li><p>Align critical behavior with production</p>
</li>
<li><p>Reproduce issues locally</p>
</li>
<li><p>Automate or document what matters</p>
</li>
</ul>
<p>If you adopt this mindset, your future and your team will thank you. Firefighting becomes predictable. Deployments are smoother. Debugging stops feeling like guesswork.</p>
<p>You’ll eventually feel more confident about your skills, cause no more myths. If it’s not working then you easily recognize the cause.</p>
<p>Logical workflow builds trust, experience and confidence.</p>
<h2 id="heading-next-articles-in-this-series">Next Articles in this Series</h2>
<p>Fixing the “works on my machine” mystery is not a one task, it’s a mindset and skill set you build over time. To tackle the root causes systematically, the following articles will dive deeper into the practical aspects of reliable PHP development environments:</p>
<ul>
<li><p><strong>Multi-PHP Versioning Without Fear</strong> – Learn how to switch safely between PHP 8.2, 8.3, and 8.5 without breaking your projects.</p>
</li>
<li><p><strong>FPM, CLI, or CGI: Why It Matters</strong> – Understand how PHP execution modes differ and why this impacts debugging and production behavior.</p>
</li>
<li><p><strong>Local Mail Done Right</strong> – Explore Mailpit, Mailhog, and strategies for debugging real SMTP flows locally.</p>
</li>
<li><p><strong>Linux Permissions Without Chmod Chaos</strong> – Avoid the common “permission denied” traps that derail even experienced developers.</p>
</li>
<li><p><strong>When Containers Actually Help</strong> – Discover when tools like Docker or Podman make sense and when they’re overkill.</p>
</li>
<li><p><strong>OS Awareness</strong> – Understand the subtle differences between Windows and Linux environments that often cause hidden bugs.</p>
</li>
<li><p><strong>Common Security Restrictions</strong> – Real-world examples of production limitations that can surprise you if not accounted for locally.</p>
</li>
<li><p><strong>XDebug: The Swiss Army Knife for Confident Developers</strong> – Harness the power of debugging like a pro.</p>
</li>
<li><p><strong>Editor — It Really Matters</strong> – Learn how your code editor can mislead you and how to configure it for reliable results.</p>
</li>
<li><p><strong>NGINX vs Apache</strong> – A practical look at architecture and behavior differences that affect local testing and production parity.</p>
</li>
</ul>
<p>Each of these articles will build on the principle introduced here: <strong>your local environment and workflow is part of the system, and it must be reliable</strong>. Together, this series will give you the tools, habits, and knowledge to debug with confidence, reproduce production issues locally, and work like a senior developer.</p>
]]></content:encoded></item><item><title><![CDATA[How to Apply Laravel Modular Approach Architecture in 9 Easy Steps]]></title><description><![CDATA[Laravel is powerful and very intelligent PHP Framework that can serve you from a very simple web application to large and enterprise level applications, Well that’s a good news but in other hand using such a large framework without any architecture a...]]></description><link>https://codelite.pro/how-to-apply-laravel-modular-approach-architecture-in-9-easy-steps</link><guid isPermaLink="true">https://codelite.pro/how-to-apply-laravel-modular-approach-architecture-in-9-easy-steps</guid><category><![CDATA[Laravel]]></category><category><![CDATA[modular]]></category><category><![CDATA[PHP]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Samer Moustafa]]></dc:creator><pubDate>Wed, 31 Dec 2025 22:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1667517437448/H8Yp-Jpad.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Laravel is powerful and very intelligent PHP Framework that can serve you from a very simple web application to large and enterprise level applications, Well that’s a good news but in other hand using such a large framework without any architecture approach in mind can lead to a massive mess and downfalls in the process of expanding and in production environment.</p>
<p>While Laravel has it’s own design system we can’t only rely on this. Imagine an Application with tons of Features that heavily depends on Each others, in this case maintaining any little refactoring or improvements can cause much problems and bugs. That’s we need to start with a modular architecture that helps separate and maintain each feature as a standalone package.</p>
<h1 id="heading-what-is-modular-architecture">What is Modular Architecture</h1>
<p>Modular Architecture is a way of your Laravel Project where each Feature is considered a standalone Block that can nicely work with other Blocks or Features. Its also serves the concept of Separation of Concerns so when you develop a Feature you have to only focus on that Feature and its Logic and how it can be used by any other Feature. So each Feature is a Module, for example we have Modules like :</p>
<pre><code class="lang-bash">Users, Blog, Pages, Products, .... etc
</code></pre>
<h1 id="heading-the-big-picture">The Big Picture</h1>
<p>In order to Apply the Modular Architecture we will need to separate each module in a dedicated directory which will contain the module’s Controller, Migrations, Views, Routes, Models, Providers and each piece of code that’s related to this Module. So we will need to instruct Laravel how to load each component of each module correctly.</p>
<p>To Achieve this separation we will rely on <a target="_blank" href="https://laravel.com/docs/9.x/providers">Service Providers</a>, where each module will contact a Module Service Provider that will instruct Laravel how to interact with and Load that Module.</p>
<h1 id="heading-create-our-project">Create our Project</h1>
<p>Lets create our laravel project which we will use to apply modular architecture</p>
<pre><code class="lang-bash">composer create-project <span class="hljs-string">"laravel/laravel"</span> modular
</code></pre>
<p>Give composer few time to download and install required packages then after installation complete go to the installation directory using <code>cd</code> command and run the <code>serve</code> command to start up our application</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> modular
php artisan serve
</code></pre>
<p>Now you can visit your application in the browser using the link <code>http://127.0.0.1:8000</code> , Note : keep eye on terminal output as the port 8000 may change.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667516792887/UrjHv2vS5.png" alt="1.png" /></p>
<h1 id="heading-modules-structure">Modules Structure</h1>
<p>We will start by creating a directory called Modules that will contain all our modules, Each Module will by consist of multiple directories and files, so our directory tree for our Modules directory will look something like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667516819285/LyeAigLbf.png" alt="2.png" /></p>
<pre><code class="lang-bash">Modules
- Blog
-- Config
-- Database
-- Http
-- Models
-- Providers
-- View
-- Routes
+ Pages
+ Products
</code></pre>
<h1 id="heading-configure-composer">Configure Composer</h1>
<p>Its very important to tell composer where to find and how to load our modules files and classes and before that we have to keep in mind that we will use namespaces to differentiate modules so each module fille will be prefixed by namespace of <code>Modules\MODULE_NAME</code> so for example</p>
<pre><code class="lang-bash">&lt;?php 
namespace Modules\Blog\Providers;

....
</code></pre>
<p>So we need to add the base namespace Modules pointing to the Modules directory in composer.json file under autoload &gt; psr-4 as follows</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667516885525/YIKPJIuw0.png" alt="3.png" /></p>
<p>don’t forget to run <code>composer dump-autoload</code> command</p>
<h1 id="heading-module-service-provider">Module Service Provider</h1>
<p>Now Composer can find our Modules classes, so it’s the time to create the module Service Provider that will instruct laravel how to interact with our module, we will apply this to our Blog module as demonstration. Go to <code>Modules &gt; Blog &gt; Providers</code> and create a new class file <code>ModuleServiceProvider.php</code>, with following contents</p>
<pre><code class="lang-bash">&lt;?php

namespace Modules\Blog\Providers;

use Illuminate\Support\ServiceProvider;

class ModuleServiceProvider extends ServiceProvider
{
    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">register</span></span>()
    {
        //...
    }

    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">boot</span></span>()
    {
        //...
    }
}
</code></pre>
<h1 id="heading-load-modules-providers">Load Modules Providers</h1>
<p>As we have seen before, each module should has it’s own Service Provider that we will use to instruct laravel how to load and interact with out module, but how laravel will know about this Service Provider ?</p>
<p>We will need to tell Laravel to Scan the Modules Directory to find installed modules and for each module we will look for the <code>ModuleServiceProvider</code> class and load it in the System. Best place to do this is in <code>AppServiceProvider.php</code> located in <code>app/Providers</code> Directory. withint the Register method as follows :</p>
<pre><code class="lang-bash">&lt;?php

namespace App\Providers;

use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    //....

    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">register</span></span>()
    {
        //Search <span class="hljs-keyword">for</span> Modules
        <span class="hljs-variable">$modulesBasePath</span> = base_path(<span class="hljs-string">'Modules'</span>);
        foreach(File::directories(<span class="hljs-variable">$modulesBasePath</span>) as <span class="hljs-variable">$moduleDirectory</span>)
        {
            //Get Module Name from the owner Directory name
            <span class="hljs-variable">$moduleName</span> = basename(<span class="hljs-variable">$moduleDirectory</span>);
            <span class="hljs-variable">$providerClassName</span> = <span class="hljs-string">'\\Modules\\'</span>.<span class="hljs-variable">$moduleName</span>.<span class="hljs-string">'\\Providers\\ModuleServiceProvider'</span>;
            <span class="hljs-keyword">if</span>(class_exists(<span class="hljs-variable">$providerClassName</span>))
            {
                //Register Module Service Provider <span class="hljs-keyword">if</span> Exist
                <span class="hljs-variable">$this</span>-&gt;app-&gt;register(<span class="hljs-variable">$providerClassName</span>);
            }
        }
    }

    //....
}
</code></pre>
<p>Now Laravel will be aware of every module Service Provider, so next steps will be all included inside that providers</p>
<h1 id="heading-routes-discovery">Routes Discovery</h1>
<p>As each module will contain its own routes then we will create a new directory into the module named <code>Routes</code> which will contain a <code>web.php</code> file, that file where we will define the module routes, and as a start will will add just one route to test if it’s working</p>
<pre><code class="lang-bash">&lt;?php

use Illuminate\Support\Facades\Route;

Route::get(<span class="hljs-string">'/blog'</span>, <span class="hljs-function"><span class="hljs-title">function</span></span>(){
    <span class="hljs-built_in">return</span> <span class="hljs-string">'Yay, Blog Routes Working'</span>;
});
</code></pre>
<p>If we tried to visit that route, it will give us 404 Not Found error as Laravel not yet aware of that file, so we will add a <code>RouteServiceProvider.php</code> that will load our <code>web.php</code> routes file, in the directory of <code>Modules/Blog/Providers</code></p>
<pre><code class="lang-bash">&lt;?php

namespace Modules\Blog\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{

    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">map</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;registerWebRoutes();
    }

    protected <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">registerWebRoutes</span></span>()
    {
        //Add Web Routes with web Guard
        Route::middleware(<span class="hljs-string">'web'</span>)
            //Set Default Controllers Namespace
            -&gt;namespace(<span class="hljs-string">'Modules\\Blog\\Http\\Controllers'</span>)
            -&gt;group(base_path(<span class="hljs-string">'Modules/Blog/Routes/web.php'</span>));
    }
}
</code></pre>
<p>Note that we are now extending the <code>Illuminate\Foundation\Support\Providers\RouteServiceProvider</code> not the regular Service provider, this will tell laravel to call the map function automatically</p>
<p>Before we test we need to tell Laravel to also load that <code>RouteServiceProvider</code> inside the register method of the <code>ModuleServiceProvider</code></p>
<pre><code class="lang-bash">&lt;?php

namespace Modules\Blog\Providers;

use Illuminate\Support\ServiceProvider;

class ModuleServiceProvider extends ServiceProvider
{
    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">register</span></span>()
    {
        //...
        <span class="hljs-variable">$this</span>-&gt;app-&gt;register(RouteServiceProvider::class);
    }

    //...
}
</code></pre>
<p>Now if we visit the test route at <code>http://127.0.0.1:8000/blog</code> it should work.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667517106991/uFae07cVa.png" alt="4.png" /></p>
<h1 id="heading-module-views">Module Views</h1>
<p>Until now we can create routes but we only return a String, what if we want to return a Blade view, and how to differentiate views for each module using views namespacing.</p>
<p>It’s very easy, all we need to do is to register our custom Views path to Laravel views sources inside the <code>ModuleServiceProvider</code> boot method</p>
<pre><code class="lang-bash">&lt;?php

namespace Modules\Blog\Providers;

use Illuminate\Support\ServiceProvider;

class ModuleServiceProvider extends ServiceProvider
{

    protected String <span class="hljs-variable">$moduleName</span> = <span class="hljs-string">'Blog'</span>;

    //...

    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">boot</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;registerViews();
        //...
    }

    protected <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">registerViews</span></span>()
    {
        <span class="hljs-variable">$moduleViewsPath</span> = __DIR__.<span class="hljs-string">'/../Views'</span>;
        <span class="hljs-variable">$this</span>-&gt;loadViewsFrom(<span class="hljs-variable">$moduleViewsPath</span>, strtolower(<span class="hljs-variable">$this</span>-&gt;moduleName));
    }
}
</code></pre>
<p>Lets test that by creating a new view inside Views directory and return it from our test route.</p>
<pre><code class="lang-bash">&lt;?php

use Illuminate\Support\Facades\Route;

Route::get(<span class="hljs-string">'/blog'</span>, <span class="hljs-function"><span class="hljs-title">function</span></span>(){
    <span class="hljs-built_in">return</span> view(<span class="hljs-string">'blog::index'</span>);
});
</code></pre>
<pre><code class="lang-bash">&lt;h1&gt;Blog Module&lt;/h1&gt;
&lt;p&gt;This view is loaded directly from Blog Module /Views directory&lt;/p&gt;
</code></pre>
<p>Continue using Controllers</p>
<p>We can take that a step further and create our first modular controller for our module at the path of <code>Modules\Blog\Http\Controllers</code> named <code>BlogController</code></p>
<pre><code class="lang-bash">&lt;?php

namespace Modules\Blog\Http\Controllers;

use Illuminate\Routing\Controller;

class BlogController extends Controller
{
    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">index</span></span>()
    {
        <span class="hljs-built_in">return</span> view(<span class="hljs-string">'blog::index'</span>);
    }
}
</code></pre>
<pre><code class="lang-bash">&lt;?php

use Illuminate\Support\Facades\Route;
use Modules\Blog\Http\Controllers\BlogController;

Route::get(<span class="hljs-string">'/blog'</span>, [BlogController::class, <span class="hljs-string">'index'</span>]);
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667517212080/gkCuXE5IL.png" alt="5.png" /></p>
<h1 id="heading-register-migrations">Register Migrations</h1>
<p>Each module may contain its own database migration, that why we need to make laravel aware of this migrations which will once again be done inside <code>ModuleServiceProvider</code> <code>boot</code> method</p>
<pre><code class="lang-bash">?php

namespace Modules\Blog\Providers;

use Illuminate\Support\ServiceProvider;

class ModuleServiceProvider extends ServiceProvider
{
    //...
    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">boot</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;registerViews();
        <span class="hljs-variable">$this</span>-&gt;registerMigrations();
        //...
    }
    //...    
    protected <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">registerMigrations</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;loadMigrationsFrom(base_path(<span class="hljs-string">'Modules/'</span>.<span class="hljs-variable">$this</span>-&gt;moduleName.<span class="hljs-string">'/Database/Migrations'</span>));
    }
    //...
}
</code></pre>
<p>Lets create a new Migration at path <code>/Modules/Blog/Database/Migrations</code> , which we will name as <code>create_posts_table.php</code></p>
<pre><code class="lang-bash">&lt;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

<span class="hljs-built_in">return</span> new class extends Migration {

    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">up</span></span>()
    {
        Schema::create(<span class="hljs-string">'posts'</span>, <span class="hljs-keyword">function</span>(Blueprint <span class="hljs-variable">$table</span>){
            <span class="hljs-variable">$table</span>-&gt;string(<span class="hljs-string">'title'</span>);
            <span class="hljs-variable">$table</span>-&gt;text(<span class="hljs-string">'content'</span>)-&gt;nullable();
            <span class="hljs-variable">$table</span>-&gt;unsignedBigInteger(<span class="hljs-string">'author_id'</span>)-&gt;default(0);
            <span class="hljs-variable">$table</span>-&gt;unsignedBigInteger(<span class="hljs-string">'category_id'</span>)-&gt;default(0);
            <span class="hljs-variable">$table</span>-&gt;timestamps();
        });
    }

    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">down</span></span>()
    {
        Schema::drop(<span class="hljs-string">'posts'</span>);
    }

};
</code></pre>
<p>Now let’s run the migration command to make sure it works</p>
<pre><code class="lang-bash">php artisan migrate
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667517299533/jbVlxj0De.png" alt="6.png" /></p>
<h1 id="heading-merge-configurations">Merge Configurations</h1>
<p>Since your modules may contains a configuration files, then we need to tell laravel to merge this files into main configurations to be able to retrieve it with <code>config()</code> function, this is once again can be done in the <code>ModuleServiceProvider</code> as follows</p>
<pre><code class="lang-bash">&lt;?php

namespace Modules\Blog\Providers;

use Illuminate\Support\ServiceProvider;

class ModuleServiceProvider extends ServiceProvider
{
    //...
    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">boot</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;registerConfig();
        //...
    }
       //...
    protected <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">registerConfig</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;mergeConfigFrom(
            base_path(<span class="hljs-string">'Modules/'</span>.<span class="hljs-variable">$this</span>-&gt;moduleName.<span class="hljs-string">'/Config/config.php'</span>), strtolower(<span class="hljs-variable">$this</span>-&gt;moduleName)
        );
    }
}
</code></pre>
<p>Now we can reference our config file using <code>config()</code> function by prefixing with the lower-case module name for example</p>
<pre><code class="lang-bash">config(<span class="hljs-string">'blog.post_per_page'</span>, 10);
</code></pre>
<h1 id="heading-models-middlewares-and-events-what-about">Models, Middlewares and Events, What about ?</h1>
<p>Those type of files is just regular classes like controllers, so laravel don’t need any extra work to be aware of as long as you use the right classes namespacing and directory structure.</p>
<p>#Final ModuleServiceProvider</p>
<pre><code class="lang-bash">&lt;?php

namespace Modules\Blog\Providers;

use Illuminate\Support\ServiceProvider;

class ModuleServiceProvider extends ServiceProvider
{

    protected String <span class="hljs-variable">$moduleName</span> = <span class="hljs-string">'Blog'</span>;

    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">register</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;app-&gt;register(RouteServiceProvider::class);
    }

    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">boot</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;registerConfig();
        <span class="hljs-variable">$this</span>-&gt;registerViews();
        <span class="hljs-variable">$this</span>-&gt;registerMigrations();
    }

    protected <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">registerViews</span></span>()
    {
        <span class="hljs-variable">$moduleViewsPath</span> = __DIR__.<span class="hljs-string">'/../Views'</span>;
        <span class="hljs-variable">$this</span>-&gt;loadViewsFrom(<span class="hljs-variable">$moduleViewsPath</span>, strtolower(<span class="hljs-variable">$this</span>-&gt;moduleName));
    }

    protected <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">registerConfig</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;mergeConfigFrom(
            base_path(<span class="hljs-string">'Modules/'</span>.<span class="hljs-variable">$this</span>-&gt;moduleName.<span class="hljs-string">'/Config/config.php'</span>), strtolower(<span class="hljs-variable">$this</span>-&gt;moduleName)
        );
    }

    protected <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">registerMigrations</span></span>()
    {
        <span class="hljs-variable">$this</span>-&gt;loadMigrationsFrom(base_path(<span class="hljs-string">'Modules/'</span>.<span class="hljs-variable">$this</span>-&gt;moduleName.<span class="hljs-string">'/Database/Migrations'</span>));
    }
}
</code></pre>
<h1 id="heading-final-words">Final Words</h1>
<p>Good Applications starts with a good structure and design pattern so it’s always the best to spend sometime designing your application structure.</p>
<p>I would also like to mention that our new Laravel Package has been release which will help developers to add Actions and Filters feature in Laravel Application like WordPress Apps, You can check out full tutorial of Eventual Events Package Here</p>
<p>Also i’m waiting for your questions and requests if you have any.</p>
]]></content:encoded></item><item><title><![CDATA[How to use Laravel Eventual Free Package from Scratch]]></title><description><![CDATA[Laravel Eventual Package is the Newly released Package for Actions and Filters Management system through Laravel Framework and PHP

Concept
In this Guide we will take a general overview about how this package work and basic concepts to get more famil...]]></description><link>https://codelite.pro/how-to-use-laravel-eventual-free-package-from-scratch</link><guid isPermaLink="true">https://codelite.pro/how-to-use-laravel-eventual-free-package-from-scratch</guid><category><![CDATA[Laravel]]></category><category><![CDATA[event listener ]]></category><category><![CDATA[WordPress]]></category><category><![CDATA[PHP]]></category><dc:creator><![CDATA[Samer Moustafa]]></dc:creator><pubDate>Thu, 18 Dec 2025 22:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1667516390812/XOCVnLt5z.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Laravel Eventual Package is the Newly released Package for Actions and Filters Management system through Laravel Framework and PHP</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667516086790/ZFyCpPVGZ.png" alt="carbon.png" /></p>
<h2 id="heading-concept">Concept</h2>
<p>In this Guide we will take a general overview about how this package work and basic concepts to get more familiar when working with Eventual Package.</p>
<p>The main purpose of this Package is to add the ability for the developer to inject code and logic pieces in a clean and standalone way, which will lead to better decoupling. Concept is inspired by WordPress Hooks System which allows developers to execute code on certain events and also filters data passing through application without touching the core code.</p>
<h3 id="heading-filters-vs-actions">Filters vs Actions</h3>
<p>We will use those terms a lot in from now on so you need to have a clear understanding of how they work and defer from each others</p>
<p>**Actions **: can be considered as an event that happens in some certain situations and may need further sequential actions to be taken upon that event, so for example consider saving a new blog post (Action), then you can inject a piece of code (Handler) to send an email to subscribers afterwards.</p>
<p>**Filters **: Actually it’s a piece of data that been collected or manipulated by the application and may need to be altered or filtered, lets say for example in our application we returning a list of blog posts in order to show it to our visitors, in this case we may want to filter this posts and exclude a private ones before returning them to the visitor</p>
<h3 id="heading-installation">Installation</h3>
<p>First make sure you have composer installed first, but in case you already working with laravel then likely you’ll have it installed already.</p>
<p>Open your terminal and CD in your laravel project root</p>
<p>Run the following composer command to install the package</p>
<pre><code class="lang-bash">composer require codersamer/eventual
</code></pre>
<p>Once installed you can start using this package.</p>
<p>Note : if you have a laravel project with version less than 6, then you’ll need to add the corresponding service provider to your application</p>
<h3 id="heading-add-service-provider-laravel-below-6">Add Service Provider (Laravel Below 6)</h3>
<p>Go to your config/app.php file and open it with your preferred code editor and add the following provider to the “providers” array</p>
<pre><code class="lang-bash">Codersamer\Eventual\Providers\EventualServiceProvider
</code></pre>
<h1 id="heading-basic-usage">Basic Usage</h1>
<p>Eventual Package depends mainly on four methods doAction, onAction, doFilter, onFilter. The “do” part means fire or apply and find the all registered handlers for that event or filter which the “on” part means when that thing happens run the following piece of code accordingly .</p>
<p>At the very basic Level we can use this methods on the Eventual Facade</p>
<pre><code class="lang-bash">Codersamer\Eventual\Facades\Eventual
</code></pre>
<h3 id="heading-register-an-action">Register an Action</h3>
<p>Before Handling an action we need to know how we fire or tell laravel that some action happening now and need to take further actions afterwards. This can be achieved simply by calling the method doAction like so</p>
<pre><code class="lang-bash">&lt;?php
using Codersamer\Eventual\Facades\Eventual;
//....
Eventual::doAction(<span class="hljs-string">'blog_post_saved'</span>, <span class="hljs-variable">$argument1</span>, <span class="hljs-variable">$argument2</span>);
</code></pre>
<p>First parameter indicates the action name that all handlers should use to respond to this action, other arguments indicates the data that will be carried to all handlers.</p>
<p>**Note **: Arguments are not limited to some number, you can pass as many arguments as you need and all of them will be carried to handlers, also it support all types of data so it can be primitive type, model, custom object … etc</p>
<p><strong>Handle an Action</strong> Now our application fires events and actions in some points of app life cycle, it’s the time for us to learn how to handle this actions and act accordingly which can be achieved by called the method **onAction **as following</p>
<pre><code class="lang-bash">&lt;?php
using Codersamer\Eventual\Facades\Eventual;
//....
Eventual::onAction(<span class="hljs-string">'blog_post_saved'</span>, <span class="hljs-keyword">function</span>(<span class="hljs-variable">$argument1</span>, <span class="hljs-variable">$argument2</span>){
    //Act to the Action
    //Send some email to subscribers
});
</code></pre>
<p>This piece of code tells Eventual Package to take some steps / run piece of code only when some action occurred, in this case it’s “blog_post_saved“, and as we mentioned before all handlers will receive the corresponding arguments been sent via the dispatcher</p>
<p><strong>Register a Filter</strong> As we registered an action before we can also register a filter before handle it later using the method doFilter , this way we can later modify that piece of data in any point of the application</p>
<pre><code class="lang-bash">&lt;?php
using Codersamer\Eventual\Facades\Eventual;
//....
<span class="hljs-variable">$post</span> = Eventual::doFilter(<span class="hljs-string">'posts_list'</span>, <span class="hljs-variable">$posts</span>, <span class="hljs-variable">$extraArgument</span>);
</code></pre>
<p>As you may notice here we could pass more than one argument to be carried on to the handlers / filters, but keep in mind that the filters system will only look for updates happen on the first argument, in this case “$posts”, also it returns the first argument again after been modified by all handlers added to this filter, so consider the extra arguments are just a reference information regarding this filter but actually the filters system doesn’t really care about it.</p>
<h3 id="heading-handle-a-filter">Handle a Filter</h3>
<p>In the Previous part we learned how to register a filter, now it’s the time to add handlers for this filter, it’s some how identical to how to handle actions but with some key differences</p>
<pre><code class="lang-bash">&lt;?php
using Codersamer\Eventual\Facades\Eventual;
....
Eventual::onFilter(<span class="hljs-string">'posts_list'</span>, <span class="hljs-keyword">function</span>(<span class="hljs-variable">$posts</span>, <span class="hljs-variable">$extraArguments</span> = null){
    //Add Updates to the posts <span class="hljs-keyword">if</span> needed, <span class="hljs-keyword">then</span> <span class="hljs-built_in">return</span> it
    <span class="hljs-built_in">return</span> <span class="hljs-variable">$posts</span>;
});
</code></pre>
<p>As you can see it’s very similar to handling actions but the key difference here is that you MUST return the first argument again after your modifications as the dispatcher now waiting for it.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Working with Filters and Actions Pattern is very fun and helps with code decoupling, so you can modify application core logic and manipulate data without touching the core code which may be useful when developing a modular laravel application, multi-theme system, multi-plugins system.</p>
<p>Now let me tell you that you are now familiar and capable of working with this package but this is not all, we have more advanced features and techniques to discuss later, so keep reading and exploring.</p>
]]></content:encoded></item><item><title><![CDATA[Javascript Fetch API Simplified]]></title><description><![CDATA[History
One of the most usages of javascript is making Requests to backends using Ajax without Page Reload. The ancient way of doing request is use XMLHttpRequest API, that was just fine but requires long code and not really simple to achieve. JQuery...]]></description><link>https://codelite.pro/javascript-fetch-api-simplified</link><guid isPermaLink="true">https://codelite.pro/javascript-fetch-api-simplified</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Ajax]]></category><category><![CDATA[fetch]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[http]]></category><dc:creator><![CDATA[Samer Moustafa]]></dc:creator><pubDate>Tue, 16 Dec 2025 22:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1643563281608/I0DH2zG-6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-history">History</h2>
<p>One of the most usages of javascript is making Requests to backends using Ajax without Page Reload. The ancient way of doing request is use XMLHttpRequest API, that was just fine but requires long code and not really simple to achieve. JQuery came to solve complexity of XMLHttpRequest and provided an API to make Ajax Requests which we so popular for long period of time.</p>
<h2 id="heading-fetch-api-compared-to-jquery-ajax">Fetch API Compared to jQuery Ajax</h2>
<ul>
<li><p>Fetch API is native to javascript, thats means it doesn't add more load to your application as jQuery do, also it makes it usable whatever JavaScript Framework you are using as it has no dependencies.</p>
</li>
<li><p>Fetch API Promise won't fail or reject on HTTP error response like 404 ... etc, instead it will just continue and set <strong>ok</strong> value to false, but it will only fails and reject on Network errors.</p>
</li>
<li><p>jQuery Ajax is just a wrapper for <strong>XMLHttpRequest</strong> so it's safer to use on very old Browsers for competabiliy but almost every modern browser now supports Fetch API.</p>
</li>
<li><p>Fetch API won't send Cookies by default, so some authentication processes may fail but of course you can set the cookies manually with initial options.</p>
</li>
<li><p>Fetch API doesn't support <strong>timeouts</strong>, which means request will keep going trying yo get response until browser decides not to. For sure you can overcome this using <strong>Promise.race()</strong> . We will learn more about this.</p>
</li>
</ul>
<h2 id="heading-getting-started">Getting Started</h2>
<p>In this tutorial we going to use <a target="_blank" href="https://jsonplaceholder.typicode.com/">JSONPlaceHolder API</a> as for demonstration purposes, it's Free and more than enough for our tutorial</p>
<p>Fetch API is totally native to Javascript so we don't need to add any packages or libraries, just a typical HTML document to work with</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"IE=edge"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Fetch API<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span>&gt;</span><span class="javascript">
        <span class="hljs-comment">//Our Javascript code to be Here</span>
    </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h2 id="heading-http-get-request">HTTP GET Request</h2>
<p>Now we going to learn how to issue a GET request to get list of posts</p>
<blockquote>
<p>EndPoint : https://jsonplaceholder.typicode.com/posts/</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-comment">//Execute one DOM Fully Loaded</span>
<span class="hljs-built_in">document</span>.addEventListener(<span class="hljs-string">'DOMContentLoaded'</span>, <span class="hljs-function">() =&gt;</span> {
     <span class="hljs-comment">//GET Request -&gt; https://jsonplaceholder.typicode.com/posts</span>
     fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts'</span>)
         .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
         .then(<span class="hljs-function"><span class="hljs-params">jsonResponse</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(jsonResponse));
});
</code></pre>
<p><strong>Code Explainations</strong></p>
<ul>
<li><p>First we wrapped our code within <strong>DOMContentLoaded</strong> event to make sure code executes once Page fully loaded to avoid any further issues.</p>
</li>
<li><p><strong>fetch</strong> function is used to issue ajax request, it takes 2 arguments. First argument indicates the endpoint or url you are issuing request to, second arguments is initial options where you can specify more options regarding your request and we don't use it here as we has nothing special. <strong>Note</strong> : fetch by default consider you are making a <strong>GET</strong> request unless you specify something else.</p>
</li>
<li><p><strong>fetch</strong> will always return a <strong>Promise</strong> that's why we used <strong>then</strong> method to chain execution after request is done</p>
</li>
<li><p>After request completed we chained it with a callback to extract Response Body as Json using <code>response.json()</code> which also will return a <strong>Promise</strong>.</p>
</li>
<li><p>Finally we chained another callback to <code>console.log</code> the Json Response to the console.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1643640670048/3WBVnyD_p.png" alt="console-log-json.png" /></p>
<p><strong>Another Example</strong></p>
<p>Let's try again to get a single post item and <code>console.log</code> its title</p>
<blockquote>
<p>EndPoint : https://jsonplaceholder.typicode.com/posts/1</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-comment">//Get Request -&gt; https://jsonplaceholder.typicode.com/posts/1</span>
fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>)
     .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
     .then(<span class="hljs-function"><span class="hljs-params">postItem</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(postItem.title));
</code></pre>
<h2 id="heading-http-post-request">HTTP POST Request</h2>
<p>Since we now know how to make GET requests then POST request won't be any hard, it's almost similar with only few points</p>
<ul>
<li><p>We need to tell Fetch API that we are using POST instead of GET</p>
</li>
<li><p>Mostly with POST requests we need to pass Data to the request</p>
</li>
<li><p>Optionally some APIs requires some headers to be sent with the Request</p>
</li>
<li><p>Also you may need to work on APIs that requires authentication and authorization. This Points can be achieved easily using the second argument of fetch method, actually it expects an object with some options modifier, so we gonna use <strong>method</strong> and <strong>body</strong> options, <strong>Optionally</strong> : we can use <strong>headers</strong> option.</p>
</li>
</ul>
<blockquote>
<p>EndPoint : https://jsonplaceholder.typicode.com/posts</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-comment">//POST Request -&gt; https://jsonplaceholder.typicode.com/posts</span>
fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts'</span>, {
    <span class="hljs-attr">method</span>: <span class="hljs-string">'POST'</span>,
    <span class="hljs-comment">//Send Data as Json String</span>
    <span class="hljs-attr">body</span>: <span class="hljs-built_in">JSON</span>.stringify({
        <span class="hljs-attr">title</span>: <span class="hljs-string">'Fetch API'</span>,
        <span class="hljs-attr">body</span>: <span class="hljs-string">'Ajax is Awesome using Fetch'</span>,
        <span class="hljs-attr">userId</span>: <span class="hljs-number">1</span>
    }),
    <span class="hljs-comment">//Set Extra Headers</span>
    <span class="hljs-attr">headers</span>: {
        <span class="hljs-string">'Content-type'</span>: <span class="hljs-string">'application/json; charset=UTF-8'</span>,
    },
})
.then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
.then(<span class="hljs-function"><span class="hljs-params">newPost</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(newPost));
</code></pre>
<h2 id="heading-http-put-request">HTTP PUT Request</h2>
<p>Its similar to POST request but we set <strong>method</strong> option to <code>PUT</code>, PUT Requests usually used to update a resources.</p>
<blockquote>
<p>EndPoint : https://jsonplaceholder.typicode.com/posts/1</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-comment">//PUT Request -&gt; https://jsonplaceholder.typicode.com/posts/1</span>
fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>, {
        <span class="hljs-attr">method</span>: <span class="hljs-string">'PUT'</span>,
        <span class="hljs-comment">//Send Data as Json String</span>
        <span class="hljs-attr">body</span>: <span class="hljs-built_in">JSON</span>.stringify({
            <span class="hljs-attr">title</span>: <span class="hljs-string">'Fetch API is Excellent'</span>,
        }),
        <span class="hljs-comment">//Set Extra Headers</span>
        <span class="hljs-attr">headers</span>: {
             <span class="hljs-string">'Content-type'</span>: <span class="hljs-string">'application/json; charset=UTF-8'</span>,
        },
    })
    .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
    .then(<span class="hljs-function"><span class="hljs-params">updatedPost</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(updatedPost));
</code></pre>
<h3 id="heading-http-delete-request">HTTP DELETE Request</h3>
<p>DELETE Request is usually used to delete a resource on server</p>
<blockquote>
<p>EndPoint : https://jsonplaceholder.typicode.com/posts/1</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-comment">//DELETE Request -&gt; https://jsonplaceholder.typicode.com/posts/1</span>
fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>, {
        <span class="hljs-attr">method</span>: <span class="hljs-string">'DELETE'</span>,
    })
    .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
    .then(<span class="hljs-function"><span class="hljs-params">jsonResponse</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(jsonResponse));
</code></pre>
<h2 id="heading-extra-bonus">Extra Bonus</h2>
<p>Now since we can work well with Fetch API it's time for some bonus tips and tricks</p>
<h3 id="heading-timeouts">Timeouts</h3>
<p>As we said before Fetch doesn't support <strong>timeouts</strong> , so how we can handle timeouts ? Well it's totally simple since fetch return a <strong>Promise</strong> so we can use <strong>race</strong> .</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//GET Request -&gt; https://jsonplaceholder.typicode.com/posts/1</span>
<span class="hljs-built_in">Promise</span>.race([
        fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>),
        <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
            <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> reject(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Request Timeout'</span>)), <span class="hljs-number">3000</span>);
         })
    ])
    .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
    .then(<span class="hljs-function"><span class="hljs-params">postItem</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(postItem.title))
    .catch(<span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> <span class="hljs-built_in">console</span>.log(error));
</code></pre>
<h2 id="heading-final-code">Final Code</h2>
<pre><code class="lang-bash">&lt;!DOCTYPE html&gt;
&lt;html lang=<span class="hljs-string">"en"</span>&gt;
&lt;head&gt;
    &lt;meta charset=<span class="hljs-string">"UTF-8"</span>&gt;
    &lt;meta http-equiv=<span class="hljs-string">"X-UA-Compatible"</span> content=<span class="hljs-string">"IE=edge"</span>&gt;
    &lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;
    &lt;title&gt;Fetch API&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;script <span class="hljs-built_in">type</span>=<span class="hljs-string">"text/javascript"</span>&gt;
        //Execute one DOM Fully Loaded
        document.addEventListener(<span class="hljs-string">'DOMContentLoaded'</span>, () =&gt; {

            //Example .1
            /** Get List of Posts
            //GET Request -&gt; https://jsonplaceholder.typicode.com/posts
            fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts'</span>)
                .<span class="hljs-keyword">then</span>(response =&gt; response.json())
                .<span class="hljs-keyword">then</span>(jsonResponse =&gt; console.log(jsonResponse));
            */

            //Example .2
            /** Get Single Post Item
            //Get Request -&gt; https://jsonplaceholder.typicode.com/posts/1
            fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>)
                .<span class="hljs-keyword">then</span>(response =&gt; response.json())
                .<span class="hljs-keyword">then</span>(postItem =&gt; console.log(postItem.title));
            */

            //Example .3
            /** Create new Post
            //POST Request -&gt; https://jsonplaceholder.typicode.com/posts
            fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts'</span>, {
                method: <span class="hljs-string">'POST'</span>,
                //Send Data as Json String
                body: JSON.stringify({
                    title: <span class="hljs-string">'Fetch API'</span>,
                    body: <span class="hljs-string">'Ajax is Awesome using Fetch'</span>,
                    userId: 1
                }),
                //Set Extra Headers
                headers: {
                    <span class="hljs-string">'Content-type'</span>: <span class="hljs-string">'application/json; charset=UTF-8'</span>,
                },
            })
            .<span class="hljs-keyword">then</span>(response =&gt; response.json())
            .<span class="hljs-keyword">then</span>(newPost =&gt; console.log(newPost));
            */

            //Example .4
            /** Update Existing Post
            //PUT Request -&gt; https://jsonplaceholder.typicode.com/posts/1
            fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>, {
                method: <span class="hljs-string">'PUT'</span>,
                //Send Data as Json String
                body: JSON.stringify({
                    title: <span class="hljs-string">'Fetch API is Excellent'</span>,
                }),
                //Set Extra Headers
                headers: {
                    <span class="hljs-string">'Content-type'</span>: <span class="hljs-string">'application/json; charset=UTF-8'</span>,
                },
            })
            .<span class="hljs-keyword">then</span>(response =&gt; response.json())
            .<span class="hljs-keyword">then</span>(updatedPost =&gt; console.log(updatedPost));
            */

            //Example .5
            /** Delete Existing Post
            //DELETE Request -&gt; https://jsonplaceholder.typicode.com/posts/1
            fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>, {
                method: <span class="hljs-string">'DELETE'</span>,
            })
            .<span class="hljs-keyword">then</span>(response =&gt; response.json())
            .<span class="hljs-keyword">then</span>(updatedPost =&gt; console.log(updatedPost));
            */

            //Bonus .1
            /** Get a Post with timeout of 3 seconds
            //GET Request -&gt; https://jsonplaceholder.typicode.com/posts/1
            Promise.race([
                fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts/1'</span>),
                new Promise((resolve, reject) =&gt; {
                    setTimeout(() =&gt; reject(new Error(<span class="hljs-string">'Request Timeout'</span>)), 3000);
                })
            ])
            .<span class="hljs-keyword">then</span>(response =&gt; response.json())
            .<span class="hljs-keyword">then</span>(postItem =&gt; console.log(postItem.title))
            .catch((error) =&gt; console.log(error));
            */

        });
    &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Create Custom Laravel Artisan Commands : Getting Started]]></title><description><![CDATA[As a Laravel developer you should be knowing what artisan is and how great addon it is to laravel, but if you are not very familiar with this then now worries, we have you covered
What is Artisan ?
ArtIsan is a Command line interface to interact with...]]></description><link>https://codelite.pro/create-custom-laravel-artisan-commands-getting-started</link><guid isPermaLink="true">https://codelite.pro/create-custom-laravel-artisan-commands-getting-started</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><category><![CDATA[console]]></category><category><![CDATA[command line]]></category><dc:creator><![CDATA[Samer Moustafa]]></dc:creator><pubDate>Tue, 09 Dec 2025 22:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1643500576523/goxxh7spA.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As a Laravel developer you should be knowing what artisan is and how great addon it is to laravel, but if you are not very familiar with this then now worries, we have you covered</p>
<h2 id="heading-what-is-artisan">What is Artisan ?</h2>
<p>ArtIsan is a Command line interface to interact with your laravel based Project, it’s shipped already with default laravel installation and you can also add it manually if not. Artisan comes with a lot of helpful and great command which helps generate and scaffold your project logic files as well as project control.</p>
<p>All artisan command can be executed simply through any command line like follows:</p>
<pre><code class="lang-bash">php artisan {command-name} {command-arguments} {command-attributes}
</code></pre>
<p>To get list of available Artisan Commands you can run this command :</p>
<pre><code class="lang-bash">php artisan list
</code></pre>
<p>Now you know the basic of Artisan Commands, so why not make your own custom artisan commands.</p>
<h2 id="heading-create-your-custom-command">Create your Custom Command</h2>
<p>Creating your custom commands will greatly help you automate and enhance your development experience, so lets image we want to make a command that will help us change users password through console interface, so we begin by create our command class file, once again we can do this using artisan command :</p>
<pre><code class="lang-bash">php artisan make:<span class="hljs-built_in">command</span> SetUserPasswordCommand
</code></pre>
<blockquote>
<p>Here we use command make:command and we passed the argument that identify the class name of our command</p>
</blockquote>
<p>Voila, your custom command class created successfully and you can found it under path : <code>/app/Console/Commands</code></p>
<p>Here is our Blank Command Class Content Looks Like</p>
<pre><code class="lang-bash">&lt;?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class SetUserPasswordCommand extends Command
{
    /**
     * The name and signature of the console <span class="hljs-built_in">command</span>.
     *
     * @var string
     */
    protected <span class="hljs-variable">$signature</span> = <span class="hljs-string">'command:name'</span>;

    /**
     * The console <span class="hljs-built_in">command</span> description.
     *
     * @var string
     */
    protected <span class="hljs-variable">$description</span> = <span class="hljs-string">'Command description'</span>;

    /**
     * Create a new <span class="hljs-built_in">command</span> instance.
     *
     * @<span class="hljs-built_in">return</span> void
     */
    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">__construct</span></span>()
    {
        parent::__construct();
    }

    /**
     * Execute the console <span class="hljs-built_in">command</span>.
     *
     * @<span class="hljs-built_in">return</span> int
     */
    public <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">handle</span></span>()
    {
        <span class="hljs-built_in">return</span> Command::SUCCESS;
    }
}
</code></pre>
<h3 id="heading-lets-deep-dive">Lets Deep dive</h3>
<p>** $signature Property : **</p>
<p>This Property is what tells laravel how you command should look like when executed, it’s like a Pattern that describe your command, so for example if we want our command to be called reset-password then the signature should be like this :</p>
<pre><code class="lang-bash">protected <span class="hljs-variable">$signature</span> = <span class="hljs-string">'reset-password'</span>;
</code></pre>
<p>** $description Property : **</p>
<p>Consider this is the Help or description for your command, so make it meaningful and descriptive, and it’s just a string, that doesn’t affect how your command executes</p>
<pre><code class="lang-php"><span class="hljs-keyword">protected</span> $description = <span class="hljs-string">'A Very Powerful command that helps you reset any user password through console'</span>;
</code></pre>
<p>** But wait… where this description will appear ? **</p>
<p>well you can check that using the artisan “help” command like this :</p>
<pre><code class="lang-bash">php artisan <span class="hljs-built_in">help</span> reset-password
</code></pre>
<p>** __construct() method : **</p>
<p>This is just a regular class constructor method that runs just before executing your command logic.</p>
<p>** handle() method : **</p>
<p>This is the beating heart of your command, this the place where you command logic should reside, which means all logic procedures should be implemented there.</p>
<p>Now we know how this command structured but its actually doing nothing, and to be useful we need to accept arguments or parameters from the console to be more dynamic and responsive</p>
<h2 id="heading-arguments">Arguments</h2>
<p>We need our Command to accept 2 Arguments (user email and the new password), if we try to just pass it when calling or command like this :</p>
<pre><code class="lang-bash">php artisan reset-password email@codersam.online TheNewPassword
</code></pre>
<p>as you may notice it will throw an Error</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1643501128489/aV0pC9BFg.png" alt="no-arguments-expected.png" /></p>
<h3 id="heading-defining-arguments">Defining Arguments</h3>
<p>That’s means we need to tell laravel that our command can except 2 arguments, and this is done by modifying command <strong>$signature</strong> as follows :</p>
<pre><code class="lang-php"><span class="hljs-keyword">protected</span> $signature = <span class="hljs-string">'reset-password {email} {password}'</span>;
</code></pre>
<p>Defining Arguments should be enclosed with curly braces ( <strong>{ }</strong> ), to identify that this is an argument that our command can accept, and between the curly braces we give our arguments a name so we can retrieve the argument value later.</p>
<h3 id="heading-retrieve-arguments-values">Retrieve Arguments Values</h3>
<p>Retrieving Arguments Value is very simple by calling the method argument, it accepts argument name as a parameter, so in our handle method we can retrieve values as follows :</p>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"></span>)
</span>{
    $email = <span class="hljs-keyword">$this</span>-&gt;argument(<span class="hljs-string">'email'</span>);
    $password = <span class="hljs-keyword">$this</span>-&gt;argument(<span class="hljs-string">'password'</span>);
    <span class="hljs-keyword">return</span> Command::SUCCESS;
}
</code></pre>
<h2 id="heading-output-to-console">Output to Console</h2>
<p>Now we can create a command, define arguments and also retrieve its values, but it will be so mystery if we can’t return a feedback to console to tell if something went successful or failed, so we need to output some messages to the console as a feedback.</p>
<h3 id="heading-the-legacy-echo">The Legacy Echo</h3>
<p>Of course as this is just a php code then you can use a simple echo to output some messages to console</p>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"></span>)
</span>{
  $email = <span class="hljs-keyword">$this</span>-&gt;argument(<span class="hljs-string">'email'</span>);
  $password = <span class="hljs-keyword">$this</span>-&gt;argument(<span class="hljs-string">'password'</span>);
  <span class="hljs-keyword">echo</span> <span class="hljs-string">'Email : '</span>.$email;
  <span class="hljs-keyword">return</span> Command::SUCCESS;
}
</code></pre>
<p>Sure it works but it’s not the best and beneficial way to output to console. Laravel Artisan comes with so many helpers to help interact with the console during command execution, we will learn about some of them just right now.</p>
<h3 id="heading-info-output">Info Output</h3>
<p>We can output a info message with the helper method of info</p>
<pre><code class="lang-php"><span class="hljs-keyword">$this</span>-&gt;info(<span class="hljs-string">'We Receive your Email and new Password'</span>);
</code></pre>
<h3 id="heading-error-output">Error Output</h3>
<p>Display errors to console can be done using helper method error</p>
<pre><code class="lang-php"><span class="hljs-keyword">$this</span>-&gt;error(<span class="hljs-string">'We cannot find a user associated with this email address'</span>);
</code></pre>
<h3 id="heading-warning-output">Warning Output</h3>
<p>You can add warning to console using helper method <strong>warn</strong></p>
<pre><code class="lang-php"><span class="hljs-keyword">$this</span>-&gt;warn(<span class="hljs-string">'Changing Password cannot be reverted later'</span>);
</code></pre>
<h3 id="heading-alert-output">Alert Output</h3>
<p>Displaying Alert can be done using helper method of <strong>alert</strong></p>
<pre><code class="lang-php"><span class="hljs-keyword">$this</span>-&gt;alert(<span class="hljs-string">'Changing Password in Progress'</span>);
</code></pre>
<p><strong>Note</strong> : Alerts may seems same like Warning but actually it has more decorated like to bring more attention</p>
<h3 id="heading-empty-lines-output">Empty Lines Output</h3>
<p>You may need to add Empty Lines like line breaks to space your outputs away, this can be done using helper method <strong>newLine</strong></p>
<pre><code class="lang-php"><span class="hljs-keyword">$this</span>-&gt;newLine();
</code></pre>
<p>Note if you need to add more than one empty line then you can pass number of lines to this method</p>
<pre><code class="lang-php"><span class="hljs-keyword">$this</span>-&gt;newLine(<span class="hljs-number">3</span>);
</code></pre>
<h2 id="heading-lets-implement-our-command">Let’s Implement our Command</h2>
<p>Now we have all knowledge need to create our command, so let’s sum it up and implement our command login to be like so</p>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"></span>)
</span>{
  $email = <span class="hljs-keyword">$this</span>-&gt;argument(<span class="hljs-string">'email'</span>);
  $password = <span class="hljs-keyword">$this</span>-&gt;argument(<span class="hljs-string">'password'</span>);

  $user = User::where(<span class="hljs-string">'email'</span>, $email)-&gt;first();

  <span class="hljs-keyword">if</span>($user == <span class="hljs-literal">null</span>)
  {
    <span class="hljs-keyword">$this</span>-&gt;error(<span class="hljs-string">'Cannot find user associated with this email address'</span>);
    <span class="hljs-keyword">return</span> Command::INVALID;
  }

  $user-&gt;password= bcrypt($password);
  $user-&gt;save();

  <span class="hljs-keyword">$this</span>-&gt;info(<span class="hljs-string">'User '</span>.$user-&gt;name.<span class="hljs-string">' Password has been changed successfully'</span>);

  <span class="hljs-keyword">return</span> Command::SUCCESS;
}
</code></pre>
<h2 id="heading-note-about-return">Note About Return</h2>
<p>Note that Laravel expects the handle method to return an Integer value which indicates the status of the command execution and we have 3 statuses that we can return as they are defined as a constants in the base Command class : **Command::SUCCESS ** , **Command::FAILURE ** and **Command::INVALID ** .</p>
<h2 id="heading-final-code">Final Code</h2>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Commands</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Command</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SetUserPasswordCommand</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Command</span>
</span>{
    <span class="hljs-comment">/**
     * The name and signature of the console command.
     *
     * <span class="hljs-doctag">@var</span> string
     */</span>
    <span class="hljs-keyword">protected</span> $signature = <span class="hljs-string">'reset-password {email} {password}'</span>;

    <span class="hljs-comment">/**
     * The console command description.
     *
     * <span class="hljs-doctag">@var</span> string
     */</span>
    <span class="hljs-keyword">protected</span> $description = <span class="hljs-string">'A Very Powerful command that helps you reset any user password through console'</span>;

    <span class="hljs-comment">/**
     * Create a new command instance.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-built_in">parent</span>::__construct();
    }

    <span class="hljs-comment">/**
     * Execute the console command.
     *
     * <span class="hljs-doctag">@return</span> int
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"></span>)
    </span>{
        $email = <span class="hljs-keyword">$this</span>-&gt;argument(<span class="hljs-string">'email'</span>);
        $password = <span class="hljs-keyword">$this</span>-&gt;argument(<span class="hljs-string">'password'</span>);

        $user = User::where(<span class="hljs-string">'email'</span>, $email)-&gt;first();

        <span class="hljs-keyword">if</span>($user == <span class="hljs-literal">null</span>)
        {
            <span class="hljs-keyword">$this</span>-&gt;error(<span class="hljs-string">'Cannot find user associated with this email address'</span>);
            <span class="hljs-keyword">return</span> Command::INVALID;
        }

        $user-&gt;password= bcrypt($password);
        $user-&gt;save();

        <span class="hljs-keyword">$this</span>-&gt;info(<span class="hljs-string">'User '</span>.$user-&gt;name.<span class="hljs-string">' Password has been changed successfully'</span>);

        <span class="hljs-keyword">return</span> Command::SUCCESS;
    }
}
</code></pre>
<h2 id="heading-summary">Summary</h2>
<p>In this tutorial we learned how to create our first Artisan command, Defining Arguments, Get Values, Display Feedback and Real world example of implementation.</p>
<p>In Next Part we will go more advanced with custom Artisan Commands and we will learn much more advanced features and techniques.</p>
<p>So if you have any questions or requests, please don’t hesitate to add it to comments below.</p>
]]></content:encoded></item></channel></rss>