<?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[Raja Muhammad Asher - Senior Software Engineer - Full Stack Developer]]></title><description><![CDATA[Build Innovative Digital Solutions using PHP, Laravel, NodeJS, ExpressJS, ReactJS, Livewire, Tailwind CSS, Bootstrap, REST, GraphQL]]></description><link>https://rajamuhammadasher.com</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 22:10:10 GMT</lastBuildDate><atom:link href="https://rajamuhammadasher.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Improve Laravel development experience]]></title><description><![CDATA[Add it to the boot method of the AppServiceProvider of the app to improve Laravel developmet experience.
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class AppServiceProvider extends ServiceProvider
{
    //...

    pub...]]></description><link>https://rajamuhammadasher.com/improve-laravel-development-experience</link><guid isPermaLink="true">https://rajamuhammadasher.com/improve-laravel-development-experience</guid><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 09 Mar 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/Y5yxdx2a4PI/upload/1f5a28c5ce71263ae546adcf2a80e4c4.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Add it to the boot method of the AppServiceProvider of the app to improve Laravel developmet experience.</p>
<pre><code class="lang-php"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">DB</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AppServiceProvider</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">ServiceProvider</span>
</span>{
    <span class="hljs-comment">//...</span>

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">boot</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span>
    </span>{
        Model::shouldBeStrict();
        Model::unguard();
        DB::prohibitDestructiveCommands(app()-&gt;isProduction());
        Date::use(CarbonImmutable::class);
    }
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Add Calendly to Nextjs 13]]></title><description><![CDATA[There is a plugin available for reactjs that one can use to add Calendly to Nextjs i.e., react-calendly. The problem is if you want to customize the button to open popup or modal then you need to have Calendly's pro plan for it.
Here is the alternati...]]></description><link>https://rajamuhammadasher.com/add-calendly-to-nextjs-13</link><guid isPermaLink="true">https://rajamuhammadasher.com/add-calendly-to-nextjs-13</guid><category><![CDATA[Next.js]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 02 Mar 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/BRBjShcA8D4/upload/473628cea3c01300332d1aeed4110dfd.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>There is a plugin available for reactjs that one can use to add Calendly to Nextjs i.e., <a target="_blank" href="https://www.npmjs.com/package/react-calendly"><strong>react-calendly</strong></a>. The problem is if you want to customize the button to open popup or modal then you need to have Calendly's pro plan for it.</p>
<p>Here is the alternative for styling button as per your requirements with free Calendly's plan. Create a client-side component and then include it where you would like to display that button. You can pass the title as props to display on the button.</p>
<p>Here I styled the button as a link.</p>
<pre><code class="lang-javascript"><span class="hljs-string">"use client"</span>;

<span class="hljs-keyword">const</span> Calendlypopup = <span class="hljs-function">(<span class="hljs-params">{ title }</span>) =&gt;</span> {
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleClick</span>(<span class="hljs-params"></span>) </span>{
    Calendly.initPopupWidget({
      <span class="hljs-attr">url</span>: <span class="hljs-string">"https://calendly.com/your_scheduling_page"</span>,
    });
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">script</span>
        <span class="hljs-attr">src</span>=<span class="hljs-string">"https://assets.calendly.com/assets/external/widget.js"</span>
        <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span>
      /&gt;</span><span class="xml">
      <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
        <span class="hljs-attr">href</span>=<span class="hljs-string">"https://assets.calendly.com/assets/external/widget.css"</span>
        <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>
      /&gt;</span>

      <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
        <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span>
          <span class="hljs-attr">border:</span> "<span class="hljs-attr">none</span>",
          <span class="hljs-attr">background:</span> "#<span class="hljs-attr">ffffff</span>",
          <span class="hljs-attr">color:</span> "#<span class="hljs-attr">6c757d</span>",
          <span class="hljs-attr">padding:</span> "<span class="hljs-attr">0</span>",
        }}
        <span class="hljs-attr">onClick</span>=<span class="hljs-string">{handleClick}</span>
      &gt;</span>
        {title}
      <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Calendlypopup;
</code></pre>
]]></content:encoded></item><item><title><![CDATA[DbGate - The Smartest SQL+noSQL Database Client]]></title><description><![CDATA[After shifting to Ubuntu from Windows, I constantly look up for the alternatives of the tools that are available in Windows to enhance my arsenal in Linux.
DbGate is the smartest SQL+noSQL database client. It works on Windows, Linux, MacOS and in web...]]></description><link>https://rajamuhammadasher.com/dbgate-the-smartest-sqlnosql-database-client</link><guid isPermaLink="true">https://rajamuhammadasher.com/dbgate-the-smartest-sqlnosql-database-client</guid><category><![CDATA[Databases]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 24 Feb 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/lRoX0shwjUQ/upload/84ecb0077e266ed67dd8b59b2cb47d33.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>After shifting to Ubuntu from Windows, I constantly look up for the alternatives of the tools that are available in Windows to enhance my arsenal in Linux.</p>
<p><a target="_blank" href="https://dbgate.org/"><strong>DbGate</strong></a> is the smartest SQL+noSQL database client. It works on Windows, Linux, MacOS and in web browser. You can connect with MySQL, PostgreSQL, MS SQL, Oracle, MongoDB, SQLite and others. It is free and open source.</p>
]]></content:encoded></item><item><title><![CDATA[Add responsive video to Nextjs using Bootstrap5]]></title><description><![CDATA[<div className="ratio ratio-16x9">
  <video width="900" height="650" muted playsInline autoPlay loop>
    <source src="/images/test.mp4" type="video/mp4" />
  </video>
</div>]]></description><link>https://rajamuhammadasher.com/add-responsive-video-to-nextjs-using-bootstrap5</link><guid isPermaLink="true">https://rajamuhammadasher.com/add-responsive-video-to-nextjs-using-bootstrap5</guid><category><![CDATA[Next.js]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 17 Feb 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/niUkImZcSP8/upload/9a1f2a9688bfb1ef2d7c0a1246283c67.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<pre><code class="lang-javascript">&lt;div className=<span class="hljs-string">"ratio ratio-16x9"</span>&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">video</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"900"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"650"</span> <span class="hljs-attr">muted</span> <span class="hljs-attr">playsInline</span> <span class="hljs-attr">autoPlay</span> <span class="hljs-attr">loop</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">source</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"/images/test.mp4"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"video/mp4"</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">video</span>&gt;</span></span>
&lt;/div&gt;
</code></pre>
]]></content:encoded></item><item><title><![CDATA[How to create a middleware in Laravel?]]></title><description><![CDATA[Creating middleware in Laravel is a common task that helps to filter HTTP requests entering your application. Middleware can perform various tasks such as authentication, logging, and modifying request/response objects.
Step 1: Create Middleware
You ...]]></description><link>https://rajamuhammadasher.com/how-to-create-a-middleware-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/how-to-create-a-middleware-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 10 Feb 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/11B4psexgj0/upload/ca101a0809d3442616b0cec89c072d97.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Creating middleware in Laravel is a common task that helps to filter HTTP requests entering your application. Middleware can perform various tasks such as authentication, logging, and modifying request/response objects.</p>
<h3 id="heading-step-1-create-middleware">Step 1: Create Middleware</h3>
<p>You can create middleware using the Artisan command-line tool. Open your terminal and run the following command:</p>
<pre><code class="lang-php">php artisan make:middleware CheckAge
</code></pre>
<p>This will create a new middleware class named <code>CheckAge</code> in the <code>app/Http/Middleware</code> directory.</p>
<h3 id="heading-step-2-define-middleware-logic">Step 2: Define Middleware Logic</h3>
<p>Open the newly created middleware file (<code>app/Http/Middleware/CheckAge.php</code>) and define the logic you want to apply. For example, you might want to check if the user is above a certain age:</p>
<pre><code class="lang-php"><span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Middleware</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Closure</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CheckAge</span>
</span>{
    <span class="hljs-comment">/**
     * Handle an incoming request.
     *
     * <span class="hljs-doctag">@param</span>  \Illuminate\Http\Request  $request
     * <span class="hljs-doctag">@param</span>  \Closure  $next
     * <span class="hljs-doctag">@return</span> mixed
     */</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">Request $request, <span class="hljs-built_in">Closure</span> $next</span>)
    </span>{
        <span class="hljs-keyword">if</span> ($request-&gt;age &lt;= <span class="hljs-number">18</span>) {
            <span class="hljs-keyword">return</span> redirect(<span class="hljs-string">'home'</span>);
        }

        <span class="hljs-keyword">return</span> $next($request);
    }
}
</code></pre>
<p>In this example, the middleware checks if the <code>age</code> parameter in the request is less than or equal to 18. If so, it redirects the user to the <code>home</code> route. Otherwise, it allows the request to proceed further.</p>
<h3 id="heading-step-3-register-middleware">Step 3: Register Middleware</h3>
<p>You need to register your middleware in the <code>app/Http/Kernel.php</code> file. Middleware can be registered globally, assigned to specific routes, or grouped.</p>
<h4 id="heading-registering-globally">Registering Globally</h4>
<p>To apply middleware to every request globally, add it to the <code>$middleware</code> array in the <code>app/Http/Kernel.php</code> file:</p>
<pre><code class="lang-php"><span class="hljs-keyword">protected</span> $middleware = [
    <span class="hljs-comment">// ...</span>
    \App\Http\Middleware\CheckAge::class,
];
</code></pre>
<h4 id="heading-registering-as-route-middleware">Registering as Route Middleware</h4>
<p>If you want to use the middleware on specific routes, add it to the <code>$routeMiddleware</code> array:</p>
<pre><code class="lang-php"><span class="hljs-keyword">protected</span> $routeMiddleware = [
    <span class="hljs-comment">// ...</span>
    <span class="hljs-string">'check.age'</span> =&gt; \App\Http/Middleware\CheckAge::class,
];
</code></pre>
<h3 id="heading-step-4-use-middleware-in-routes">Step 4: Use Middleware in Routes</h3>
<p>Once the middleware is registered, you can use it in your routes or controllers. Open the <code>routes/web.php</code> file and apply the middleware to specific routes:</p>
<pre><code class="lang-php">Route::get(<span class="hljs-string">'profile'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// Only users older than 18 can access this route</span>
})-&gt;middleware(<span class="hljs-string">'check.age'</span>);
</code></pre>
<p>Or apply it to a group of routes:</p>
<pre><code class="lang-php">Route::group([<span class="hljs-string">'middleware'</span> =&gt; [<span class="hljs-string">'check.age'</span>]], <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    Route::get(<span class="hljs-string">'profile'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        <span class="hljs-comment">// Only users older than 18 can access this route</span>
    });

    Route::get(<span class="hljs-string">'settings'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        <span class="hljs-comment">// Only users older than 18 can access this route</span>
    });
});
</code></pre>
<h3 id="heading-step-5-testing-middleware">Step 5: Testing Middleware</h3>
<p>You should test your middleware to ensure it works as expected. Create test cases or manually test different scenarios to verify the middleware's behavior.</p>
<h3 id="heading-example-test-scenario">Example Test Scenario</h3>
<p>To manually test, you can use a URL with different <code>age</code> query parameters to see if the redirection works:</p>
<pre><code class="lang-php">httpCopy codehttp:<span class="hljs-comment">//your-app.test/profile?age=17  // This should redirect to 'home'</span>
http:<span class="hljs-comment">//your-app.test/profile?age=19  // This should allow access to 'profile'</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Explain register and boot methods in the service provider class.]]></title><description><![CDATA[A service provider is responsible for binding services into the service container, which makes them available for dependency injection.
register: This method is used to bind services into the service container. You should use it to define any binding...]]></description><link>https://rajamuhammadasher.com/explain-register-and-boot-methods-in-the-service-provider-class</link><guid isPermaLink="true">https://rajamuhammadasher.com/explain-register-and-boot-methods-in-the-service-provider-class</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 03 Feb 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/MHS7g_q-6mE/upload/d2a747e2061249aad092ae1ec2feed64.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A service provider is responsible for binding services into the service container, which makes them available for dependency injection.</p>
<p><strong>register</strong>: This method is used to bind services into the service container. You should use it to define any bindings or singletons that your application needs. The <code>register</code> method is called first, so it is the place to configure and register services before they are needed by your application.</p>
<p><strong>boot</strong>: This method is used to perform any actions that need to happen after all services are registered. It is ideal for event listeners, route registrations, or any other setup that requires the services to be fully registered and available.</p>
]]></content:encoded></item><item><title><![CDATA[Describe the service provider in Laravel]]></title><description><![CDATA[In Laravel, a service provider is a central piece of the framework's architecture that is responsible for bootstrapping and configuring services and resources used by your application. They play a crucial role in Laravel's dependency injection and se...]]></description><link>https://rajamuhammadasher.com/describe-the-service-provider-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/describe-the-service-provider-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 27 Jan 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/aielvGxZB0g/upload/eff02569c7aae2a415a7a985c416722b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In Laravel, a service provider is a central piece of the framework's architecture that is responsible for bootstrapping and configuring services and resources used by your application. They play a crucial role in Laravel's dependency injection and service container systems. Here’s a breakdown of what a service provider is and what it does:</p>
<h3 id="heading-key-responsibilities-of-a-service-provider">Key Responsibilities of a Service Provider</h3>
<ol>
<li><p><strong>Register Services</strong>:</p>
<ul>
<li>Service providers are primarily responsible for binding classes and interfaces to the service container. This involves registering services that your application might need. This is done in the <code>register</code> method.</li>
</ul>
</li>
<li><p><strong>Bootstrapping Services</strong>:</p>
<ul>
<li>After all services are registered, Laravel calls the <code>boot</code> method on each service provider. This is where you can perform any actions required to bootstrap your application, such as event listeners, route bindings, or middleware registration.</li>
</ul>
</li>
</ol>
<h3 id="heading-lifecycle-of-service-providers">Lifecycle of Service Providers</h3>
<ol>
<li><p><strong>Service Provider Registration</strong>:</p>
<ul>
<li>Laravel loads service providers as defined in the <code>config/app.php</code> file within the <code>providers</code> array. This file lists all the service providers to be registered.</li>
</ul>
</li>
<li><p><strong>Service Provider Execution</strong>:</p>
<ul>
<li><p>When the application is bootstrapped, Laravel first executes the <code>register</code> method of all providers. This allows the service container to register all necessary bindings.</p>
</li>
<li><p>After all <code>register</code> methods have been called, Laravel calls the <code>boot</code> method on each provider. This ensures that all services are registered before they are bootstrapped.</p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-common-uses-of-service-providers">Common Uses of Service Providers</h3>
<ul>
<li><p><strong>Binding Services to the Container</strong>:</p>
<ul>
<li>Service providers are used to bind various services, repositories, or other components to the Laravel service container, allowing for dependency injection throughout the application.</li>
</ul>
</li>
<li><p><strong>Event Listeners and Subscribers</strong>:</p>
<ul>
<li>Registering event listeners and subscribers is often done within the <code>boot</code> method of service providers.</li>
</ul>
</li>
<li><p><strong>Configuration and Setup</strong>:</p>
<ul>
<li>Setting up configuration values or performing initial setup tasks, such as loading routes or views, can be handled in service providers.</li>
</ul>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Which Artisan command gives a list of available commands?]]></title><description><![CDATA[In Laravel, you can get a list of all available artisan commands by using the following command in your terminal:
php artisan list

This will display a comprehensive list of all the commands that you can run with artisan, along with a brief descripti...]]></description><link>https://rajamuhammadasher.com/which-artisan-command-gives-a-list-of-available-commands</link><guid isPermaLink="true">https://rajamuhammadasher.com/which-artisan-command-gives-a-list-of-available-commands</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 20 Jan 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/kNsAF3gcyeY/upload/9c0656913ec3a431fa018c450d3627ff.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In Laravel, you can get a list of all available artisan commands by using the following command in your terminal:</p>
<pre><code class="lang-php">php artisan <span class="hljs-keyword">list</span>
</code></pre>
<p>This will display a comprehensive list of all the commands that you can run with artisan, along with a brief description of each command.</p>
]]></content:encoded></item><item><title><![CDATA[What is the use of Bundles in Laravel?]]></title><description><![CDATA[In Laravel, "bundles" are commonly referred to as "packages" in more recent terminology. Packages in Laravel are a way to group related functionality, libraries, and resources that can be shared and reused across multiple projects. They can be create...]]></description><link>https://rajamuhammadasher.com/what-is-the-use-of-bundles-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-is-the-use-of-bundles-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 13 Jan 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/zwCE12DucBo/upload/4c5e030b4b49c7d5a38d0960ae8e8e71.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In Laravel, "bundles" are commonly referred to as "packages" in more recent terminology. Packages in Laravel are a way to group related functionality, libraries, and resources that can be shared and reused across multiple projects. They can be created and managed by the Laravel community or by individual developers. Here are the primary uses and benefits of using bundles (packages) in Laravel:</p>
<ol>
<li><p><strong>Reusability</strong>: Packages allow developers to create reusable pieces of code that can be used across different Laravel projects. This reduces the need to write the same code multiple times.</p>
</li>
<li><p><strong>Modularity</strong>: By separating functionality into packages, you can keep your codebase clean and modular. Each package can focus on a specific functionality or feature, making it easier to manage and maintain.</p>
</li>
<li><p><strong>Community Contributions</strong>: Many packages are created and maintained by the Laravel community. These packages can provide a wide range of functionalities, from simple utilities to complex features, which can be integrated into your Laravel application.</p>
</li>
<li><p><strong>Easier Maintenance</strong>: By isolating certain features into packages, you can update and maintain those features independently of the main application. This isolation helps in managing dependencies and versioning more effectively.</p>
</li>
<li><p><strong>Quick Integration</strong>: Packages can be easily integrated into a Laravel application using Composer, which is a dependency management tool. This allows for quick and seamless installation and updating of packages.</p>
</li>
<li><p><strong>Encapsulation</strong>: Packages encapsulate functionality, which helps in maintaining a clear separation of concerns within the application. This makes the application architecture more robust and easier to understand.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Explain ORM in Laravel]]></title><description><![CDATA[ORM (Object-Relational Mapping) in Laravel is a technique used to convert data between incompatible type systems in object-oriented programming languages. In Laravel, the ORM system is provided by Eloquent, which is a powerful and elegant ActiveRecor...]]></description><link>https://rajamuhammadasher.com/explain-orm-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/explain-orm-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 06 Jan 2024 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/XaQhfvuCVz4/upload/732009e24dc145c056128338a6f26dde.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>ORM (Object-Relational Mapping) in Laravel is a technique used to convert data between incompatible type systems in object-oriented programming languages. In Laravel, the ORM system is provided by Eloquent, which is a powerful and elegant ActiveRecord implementation for working with your database.</p>
<h3 id="heading-1-models">1. Models</h3>
<p>Models in Laravel represent the data structure of your application and are typically stored in the <code>app/Models</code> directory. Each Eloquent model corresponds to a database table. For example, a <code>User</code> model will interact with the <code>users</code> table in the database.</p>
<h3 id="heading-2-relationships">2. Relationships</h3>
<p>Eloquent makes it easy to define relationships between different models. For example, a <code>User</code> might have many <code>Post</code> models.</p>
<h3 id="heading-3-query-builder">3. Query Builder</h3>
<p>Eloquent provides an expressive and easy-to-use query builder to interact with the database. You can perform CRUD operations with simple methods.</p>
<h3 id="heading-4-mutators-and-accessors">4. Mutators and Accessors</h3>
<p>Eloquent allows you to define mutators and accessors to modify how attributes are retrieved or set.</p>
<h3 id="heading-5-migrations">5. Migrations</h3>
<p>Laravel uses migrations to manage database schema changes. This ensures that your database structure is consistent across different environments.</p>
]]></content:encoded></item><item><title><![CDATA[What is Nova?]]></title><description><![CDATA[Laravel Nova is an administrative dashboard designed for Laravel web applications. It provides a polished and customizable interface for managing data within your application. Developed by the Laravel team, Nova integrates seamlessly with Laravel, of...]]></description><link>https://rajamuhammadasher.com/what-is-nova</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-is-nova</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 30 Dec 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/2vSivos6YYQ/upload/789076f124addc705c06d89eabaf99a2.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Laravel Nova is an administrative dashboard designed for Laravel web applications. It provides a polished and customizable interface for managing data within your application. Developed by the Laravel team, Nova integrates seamlessly with Laravel, offering a range of features that make it a powerful tool for developers looking to build admin panels quickly and efficiently. Here are some of its key features:</p>
<ol>
<li><p><strong>Resource Management</strong>: Nova allows you to define resources, which represent the models in your application. Each resource can be managed through a set of predefined interfaces for creating, reading, updating, and deleting (CRUD) records.</p>
</li>
<li><p><strong>Custom Tools</strong>: You can extend Nova by creating custom tools. This allows you to add specific functionalities that are not available out-of-the-box, catering to the unique needs of your application.</p>
</li>
<li><p><strong>Lenses</strong>: Lenses provide a way to define custom queries and views for your resources. This is useful for creating specialized views of your data that go beyond the standard resource listing.</p>
</li>
<li><p><strong>Actions</strong>: Actions in Nova let you perform tasks on a resource or multiple resources. For example, you can define an action to send emails to selected users or to perform batch updates.</p>
</li>
<li><p><strong>Metrics</strong>: Nova includes support for creating custom metrics, allowing you to display insightful data and trends within your admin dashboard. These metrics can be displayed as value metrics, trend metrics, or partition metrics.</p>
</li>
<li><p><strong>Filters</strong>: Filters allow users to narrow down the displayed data according to specific criteria. Nova makes it easy to define these filters and apply them to your resource listings.</p>
</li>
<li><p><strong>Authorization</strong>: Nova leverages Laravel's built-in authorization system to control access to resources and actions. You can define policies and gates to ensure that only authorized users can perform certain actions.</p>
</li>
<li><p><strong>Customizable UI</strong>: The appearance of Nova can be customized to fit the branding and design needs of your application. You can adjust the look and feel to ensure consistency with the rest of your application.</p>
</li>
<li><p><strong>Searchable</strong>: Nova includes powerful search capabilities, allowing users to quickly find records across all resources in the application.</p>
</li>
<li><p><strong>Localization</strong>: Nova supports multiple languages, making it a great choice for applications that need to cater to a diverse user base.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[What is a lumen?]]></title><description><![CDATA[Laravel Lumen is a micro-framework based on the Laravel framework, designed for building fast, lightweight, and efficient applications and APIs. Here are some key aspects of Laravel Lumen:

Purpose: Lumen is tailored for microservices and API develop...]]></description><link>https://rajamuhammadasher.com/what-is-a-lumen</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-is-a-lumen</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 23 Dec 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/uEQldPp1CZQ/upload/de8142debd9b2112906be2ef99e04eff.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Laravel Lumen is a micro-framework based on the Laravel framework, designed for building fast, lightweight, and efficient applications and APIs. Here are some key aspects of Laravel Lumen:</p>
<ol>
<li><p><strong>Purpose</strong>: Lumen is tailored for microservices and API development. It focuses on providing a minimalist framework that retains the essential features of Laravel without the additional overhead.</p>
</li>
<li><p><strong>Performance</strong>: Because it strips away many of Laravel's features that are not essential for building APIs, Lumen can handle requests faster and with lower latency.</p>
</li>
<li><p><strong>Similarity to Laravel</strong>: Lumen shares the same core components as Laravel, which means developers familiar with Laravel will find it easy to pick up and use Lumen. It retains a similar syntax and many of the same features, such as routing, middleware, and service providers.</p>
</li>
<li><p><strong>Components</strong>: It includes essential components like:</p>
<ul>
<li><p><strong>Routing</strong>: For defining API endpoints.</p>
</li>
<li><p><strong>Middleware</strong>: For filtering HTTP requests entering the application.</p>
</li>
<li><p><strong>Validation</strong>: For ensuring the data passed to the API meets certain criteria.</p>
</li>
<li><p><strong>Eloquent ORM</strong>: For interacting with the database.</p>
</li>
<li><p><strong>Queuing</strong>: For background job processing.</p>
</li>
</ul>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[What are the basic concepts in Laravel?]]></title><description><![CDATA[the basic concepts you need to understand to get started with Laravel:
1. MVC Architecture
Laravel follows the Model-View-Controller (MVC) design pattern, which separates the application logic into three main components:

Model: Handles the data and ...]]></description><link>https://rajamuhammadasher.com/what-are-the-basic-concepts-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-are-the-basic-concepts-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 16 Dec 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/82TpEld0_e4/upload/928a00cb7e60698cd1959dc2efcd9876.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>the basic concepts you need to understand to get started with Laravel:</p>
<h3 id="heading-1-mvc-architecture"><strong>1. MVC Architecture</strong></h3>
<p>Laravel follows the Model-View-Controller (MVC) design pattern, which separates the application logic into three main components:</p>
<ul>
<li><p><strong>Model:</strong> Handles the data and business logic.</p>
</li>
<li><p><strong>View:</strong> Responsible for the presentation layer.</p>
</li>
<li><p><strong>Controller:</strong> Acts as an intermediary between Model and View, handling user input and interactions.</p>
</li>
</ul>
<h3 id="heading-2-routing"><strong>2. Routing</strong></h3>
<p>Laravel uses a simple and expressive syntax for defining routes in the <code>routes/web.php</code> and <code>routes/api.php</code> files. Routes map URLs to specific controller actions.</p>
<h3 id="heading-3-middleware"><strong>3. Middleware</strong></h3>
<p>Middleware provides a way to filter HTTP requests entering your application. They are used for tasks like authentication, logging, and CORS. Middleware can be applied globally or to specific routes.</p>
<h3 id="heading-4-controllers"><strong>4. Controllers</strong></h3>
<p>Controllers contain the logic for handling requests and returning responses. They group related routes and actions together.</p>
<h3 id="heading-5-blade-templating-engine"><strong>5. Blade Templating Engine</strong></h3>
<p>Blade is Laravel's powerful templating engine that allows you to use plain PHP code in your views. It provides features like template inheritance, sections, and components.</p>
<h3 id="heading-6-eloquent-orm"><strong>6. Eloquent ORM</strong></h3>
<p>Eloquent is Laravel’s ORM (Object-Relational Mapper) that simplifies database interactions. Each database table has a corresponding "Model" that is used to interact with that table.</p>
<h3 id="heading-7-migrations"><strong>7. Migrations</strong></h3>
<p>Migrations are version control for your database, allowing you to define and share the application's database schema. They help in creating, modifying, and managing the database structure.</p>
<h3 id="heading-8-artisan-cli"><strong>8. Artisan CLI</strong></h3>
<p>Artisan is the command-line interface included with Laravel. It provides a number of helpful commands for application development. You can create models, controllers, migrations, and more using Artisan.</p>
<h3 id="heading-9-validation"><strong>9. Validation</strong></h3>
<p>Laravel provides a convenient way to validate incoming HTTP requests with its validation feature. You can validate data directly in the controller.</p>
<h3 id="heading-10-service-providers"><strong>10. Service Providers</strong></h3>
<p>Service providers are the central place of all Laravel application bootstrapping. They are responsible for binding things into the service container, registering event listeners, middleware, and more.</p>
<h3 id="heading-11-facades"><strong>11. Facades</strong></h3>
<p>Facades provide a "static" interface to classes that are available in the application’s service container. They provide a simple way to access services.</p>
<h3 id="heading-12-queues"><strong>12. Queues</strong></h3>
<p>Queues allow you to defer the processing of a time-consuming task, such as sending an email, until a later time. This can drastically speed up web requests to your application.</p>
<h3 id="heading-13-events-and-listeners"><strong>13. Events and Listeners</strong></h3>
<p>Laravel's event system provides a simple observer implementation, allowing you to subscribe and listen for various events that occur in your application.</p>
]]></content:encoded></item><item><title><![CDATA[What is tinker in Laravel?]]></title><description><![CDATA["Tinker" refers to an interactive REPL (Read-Evaluate-Print Loop) tool that allows developers to interact with their Laravel application from the command line in a live, interactive manner. It's similar to tools like IRB (Interactive Ruby) or the Pyt...]]></description><link>https://rajamuhammadasher.com/what-is-tinker-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-is-tinker-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 09 Dec 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/aq9ouSXaVng/upload/859ac4cd0ca068742381589bcf5160ce.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>"Tinker" refers to an interactive REPL (Read-Evaluate-Print Loop) tool that allows developers to interact with their Laravel application from the command line in a live, interactive manner. It's similar to tools like IRB (Interactive Ruby) or the Python shell.</p>
<p>When you run the <code>php artisan tinker</code> command from the command line within your Laravel project directory, you'll enter into a PHP shell with your Laravel application bootstrapped. This means you have access to all the classes, models, configurations, and services of your Laravel application directly from the command line.</p>
<p>Tinker is especially useful for quickly testing out pieces of code, running database queries, debugging, or exploring the behavior of your application interactively without having to go through the process of creating controllers, routes, or views. It's a convenient way to experiment with your Laravel application in a controlled environment. However, it's important to be cautious when using Tinker, especially in production environments, to avoid unintended changes or actions.</p>
]]></content:encoded></item><item><title><![CDATA[What are the advantages of Queue?]]></title><description><![CDATA[Queues manage and process background jobs efficiently. Here are some key benefits of using queues in Laravel:

Asynchronous Processing: One of the primary advantages of queues is enabling asynchronous processing of tasks. Instead of executing time-co...]]></description><link>https://rajamuhammadasher.com/what-are-the-advantages-of-queue</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-are-the-advantages-of-queue</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 02 Dec 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/U0QaV_H8-R4/upload/20a456cede912f9dcfe0c4991aeca074.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Queues manage and process background jobs efficiently. Here are some key benefits of using queues in Laravel:</p>
<ol>
<li><p><strong>Asynchronous Processing</strong>: One of the primary advantages of queues is enabling asynchronous processing of tasks. Instead of executing time-consuming tasks synchronously within the request-response cycle, you can push these tasks onto a queue to be processed later. This helps in keeping the application responsive and scalable.</p>
</li>
<li><p><strong>Improved Performance</strong>: Queues improve the performance of web applications by offloading tasks to be processed outside of the typical request lifecycle. This allows your application to respond quickly to incoming HTTP requests while time-consuming tasks are executed separately in the background.</p>
</li>
<li><p><strong>Scalability</strong>: Queues facilitate better scalability for your application. By processing tasks asynchronously, you can handle varying loads more effectively. You can scale the number of workers or processing servers based on the workload of your queues, ensuring optimal performance during peak times.</p>
</li>
<li><p><strong>Reduced Response Time</strong>: Since tasks are executed independently in the background, the response time of your application remains fast and consistent. Users don’t have to wait for resource-intensive tasks to complete before receiving a response.</p>
</li>
<li><p><strong>Fault Tolerance</strong>: Queues enhance fault tolerance in your application. If a queued job fails during processing, most queue drivers (like Redis or Beanstalkd) provide mechanisms to handle failed jobs, such as retrying them or moving them to a dead letter queue for analysis.</p>
</li>
<li><p><strong>Support for Delayed Jobs</strong>: Laravel queues support delayed job execution, allowing you to defer the execution of tasks until a later time or after a specific delay. This is useful for scheduling tasks or managing job priorities based on the workload.</p>
</li>
<li><p><strong>Separation of Concerns</strong>: Queues promote a clean separation of concerns in your application architecture. Business logic related to task execution can be encapsulated within job classes, while the queuing system manages the orchestration of these tasks.</p>
</li>
<li><p><strong>Integration with Monitoring and Analytics</strong>: Laravel queues often integrate well with monitoring and analytics tools. This enables you to track job processing metrics, monitor queue performance, and gain insights into the health of your background job processing system.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[What is the Repository pattern in laravel?]]></title><description><![CDATA[The Repository pattern in Laravel is a design pattern that abstracts the data access layer from the rest of the application. It provides a more structured way to handle data operations in your application by centralizing data access logic in one plac...]]></description><link>https://rajamuhammadasher.com/what-is-the-repository-pattern-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-is-the-repository-pattern-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 25 Nov 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/LG8ToawE8WQ/upload/0bf9aa64585277d5ac41615cc3c3888c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The Repository pattern in Laravel is a design pattern that abstracts the data access layer from the rest of the application. It provides a more structured way to handle data operations in your application by centralizing data access logic in one place rather than scattering it across your codebase.</p>
<p>Here’s a breakdown of how the Repository pattern works in Laravel:</p>
<ol>
<li><p><strong>Separation of Concerns</strong>: The Repository pattern separates the business logic of your application from the details of data storage and retrieval. This separation makes your application more maintainable and testable.</p>
</li>
<li><p><strong>Centralized Data Access</strong>: Instead of interacting with database models directly from your controllers or services, you interact with repositories. Repositories encapsulate the logic required to fetch and manipulate data.</p>
</li>
<li><p><strong>Encapsulation of Query Logic</strong>: Repositories encapsulate query logic within methods. For example, you might have methods like <code>getAllUsers()</code>, <code>getUserById($id)</code>, <code>createUser($data)</code>, etc., in your UserRepository.</p>
</li>
<li><p><strong>Eloquent Integration</strong>: In Laravel, repositories often utilize Eloquent ORM (Object-Relational Mapping) to interact with the database. Eloquent is Laravel's built-in ORM that simplifies database interactions by using model classes to represent database tables.</p>
</li>
<li><p><strong>Flexibility and Reusability</strong>: Using repositories allows for flexibility in changing your data storage implementation. For instance, you can switch from using Eloquent ORM to a different data storage system (like an API or another database) without changing your application's business logic.</p>
</li>
<li><p><strong>Testing</strong>: Repositories make it easier to test your application. You can mock repositories in your tests, ensuring that your tests focus solely on the business logic and not on the underlying data access mechanisms.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[How to use skip() and take() in Laravel Query?]]></title><description><![CDATA[skip() and take() are commonly used methods when querying the database to paginate or limit the number of records returned. These methods are particularly useful when you want to implement pagination or control the number of records fetched from the ...]]></description><link>https://rajamuhammadasher.com/how-to-use-skip-and-take-in-laravel-query</link><guid isPermaLink="true">https://rajamuhammadasher.com/how-to-use-skip-and-take-in-laravel-query</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 18 Nov 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/YeXSra2lYJ8/upload/89584843d3ba42fcd8dd7aeee22eb203.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><code>skip()</code> and <code>take()</code> are commonly used methods when querying the database to paginate or limit the number of records returned. These methods are particularly useful when you want to implement pagination or control the number of records fetched from the database.</p>
<pre><code class="lang-php">$users = User::skip(<span class="hljs-number">10</span>)-&gt;take(<span class="hljs-number">5</span>)-&gt;get();

is equivalent to

select * <span class="hljs-keyword">from</span> `users` limit <span class="hljs-number">5</span> offset <span class="hljs-number">10</span>;
</code></pre>
]]></content:encoded></item><item><title><![CDATA[What is composer lock in laravel?]]></title><description><![CDATA[composer.lock is a file generated by Composer, which is the dependency management tool used in PHP applications. This file plays a crucial role in ensuring that all developers and production servers use the exact same versions of packages (dependenci...]]></description><link>https://rajamuhammadasher.com/what-is-composer-lock-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-is-composer-lock-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 11 Nov 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/DoWZMPZ-M9s/upload/621a67a3220c2e2060f9d8a42aff1957.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><code>composer.lock</code> is a file generated by Composer, which is the dependency management tool used in PHP applications. This file plays a crucial role in ensuring that all developers and production servers use the exact same versions of packages (dependencies) for the project.</p>
<p>Here's what <code>composer.lock</code> does and why it's important:</p>
<ol>
<li><p><strong>Dependency Version Locking</strong>: When you run <code>composer install</code> or <code>composer update</code> to manage dependencies for your Laravel project, Composer reads the <code>composer.json</code> file to determine which packages and versions are needed.</p>
</li>
<li><p><strong>Exact Version Record</strong>: After resolving the dependencies based on <code>composer.json</code>, Composer writes the exact version numbers of all packages (including dependencies of dependencies) into <code>composer.lock</code>.</p>
</li>
<li><p><strong>Consistent Environment</strong>: The <code>composer.lock</code> file ensures that every time someone else or a different environment runs <code>composer install</code>, the exact versions of packages listed in <code>composer.lock</code> are installed. This prevents unexpected upgrades or changes in package versions that could introduce compatibility issues or bugs.</p>
</li>
<li><p><strong>Reproducibility</strong>: By committing the <code>composer.lock</code> file into version control (e.g., Git), you can reproduce the exact environment and dependencies used when the file was last updated. This is critical for ensuring consistent behavior across different development environments and deployments.</p>
</li>
<li><p><strong>Production Deployment</strong>: When deploying your Laravel application, you typically use <code>composer install</code> rather than <code>composer update</code>. This instructs Composer to install packages according to the locked versions specified in <code>composer.lock</code>, which is vital for predictable and stable deployments.</p>
</li>
</ol>
<p>In summary, <code>composer.lock</code> is a file that records the exact versions of all packages and their dependencies used in a Laravel project. It ensures consistent dependency resolution and helps maintain a stable and reproducible development and deployment environment. Always commit <code>composer.lock</code> along with <code>composer.json</code> to version control to ensure consistency across your team and deployments.</p>
]]></content:encoded></item><item><title><![CDATA[How to mock a static facade method in Laravel?]]></title><description><![CDATA[Mocking a static facade method in Laravel for testing can be achieved using a combination of Laravel's built-in features and PHPUnit.
1. Understand the Static Facade
In Laravel, static facades provide a convenient way to access Laravel services. For ...]]></description><link>https://rajamuhammadasher.com/how-to-mock-a-static-facade-method-in-laravel</link><guid isPermaLink="true">https://rajamuhammadasher.com/how-to-mock-a-static-facade-method-in-laravel</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 04 Nov 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/UeMB9yu92Do/upload/5291876ba8e17ce2914bc9063fcb6bd7.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Mocking a static facade method in Laravel for testing can be achieved using a combination of Laravel's built-in features and PHPUnit.</p>
<h3 id="heading-1-understand-the-static-facade"><strong>1. Understand the Static Facade</strong></h3>
<p>In Laravel, static facades provide a convenient way to access Laravel services. For example, <code>Config::get('key')</code> is a facade call to retrieve a configuration value.</p>
<h3 id="heading-2-install-phpunit"><strong>2. Install PHPUnit</strong></h3>
<p>Ensure that PHPUnit is set up and integrated with your Laravel project. Laravel ships with PHPUnit pre-configured, so you can start writing your tests immediately.</p>
<h3 id="heading-3-using-facades"><strong>3. Using Facades</strong></h3>
<p>Facades are typically used statically like this:</p>
<pre><code class="lang-php"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Config</span>;

$value = Config::get(<span class="hljs-string">'key'</span>);
</code></pre>
<h3 id="heading-4-mocking-the-facade"><strong>4. Mocking the Facade</strong></h3>
<p>To mock a static facade method, you'll use the <code>Facade</code> class and its <code>shouldReceive</code> method from PHPUnit.</p>
<p>For instance, let's say we want to mock the <code>Config::get()</code> method:</p>
<pre><code class="lang-php"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Config</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Facade</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExampleTest</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">TestCase</span>
</span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">testConfigGet</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-comment">// Mock the facade</span>
        Facade::shouldReceive(<span class="hljs-string">'get'</span>)
            -&gt;with(<span class="hljs-string">'key'</span>)
            -&gt;andReturn(<span class="hljs-string">'mocked value'</span>);

        <span class="hljs-comment">// Your test logic</span>
        $value = Config::get(<span class="hljs-string">'key'</span>);

        <span class="hljs-comment">// Assert the mocked value is returned</span>
        <span class="hljs-keyword">$this</span>-&gt;assertEquals(<span class="hljs-string">'mocked value'</span>, $value);
    }
}
</code></pre>
<h3 id="heading-5-explanation"><strong>5. Explanation</strong></h3>
<ul>
<li><p><strong>Facade::shouldReceive('get')</strong>: This sets up an expectation that the <code>get</code> method of the <code>Config</code> facade will be called.</p>
</li>
<li><p><strong>-&gt;with('key')</strong>: Specifies that the <code>get</code> method should be called with the argument <code>'key'</code>.</p>
</li>
<li><p><strong>-&gt;andReturn('mocked value')</strong>: Specifies the return value when the <code>get</code> method is called with <code>'key'</code>.</p>
</li>
</ul>
<h3 id="heading-6-running-the-test"><strong>6. Running the Test</strong></h3>
<p>Run your PHPUnit tests.</p>
<h3 id="heading-additional-tips"><strong>Additional Tips:</strong></h3>
<ul>
<li><p><strong>Use Namespaces</strong>: Ensure you're importing the correct facade and Facade class.</p>
</li>
<li><p><strong>Isolate Tests</strong>: Each test should be independent and ideally only test one piece of functionality.</p>
</li>
<li><p><strong>Reset Mocks</strong>: If you need to reset mocks between tests, use <code>Facade::clearResolvedInstances();</code> to clear resolved instances.</p>
</li>
</ul>
<p>By following these steps, you can effectively mock static facade methods in Laravel for testing purposes. This approach allows you to control the behavior of Laravel facades within your test environment.</p>
]]></content:encoded></item><item><title><![CDATA[What is Auth? How is it used?]]></title><description><![CDATA["Auth" refers to the authentication system provided by the framework to manage user authentication, including user login, registration, password reset, and session management.
The "Auth" system in Laravel is based on guards and providers. Here’s a br...]]></description><link>https://rajamuhammadasher.com/what-is-auth-how-is-it-used</link><guid isPermaLink="true">https://rajamuhammadasher.com/what-is-auth-how-is-it-used</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><dc:creator><![CDATA[Raja Muhammad Asher]]></dc:creator><pubDate>Sat, 28 Oct 2023 19:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/RMIsZlv8qv4/upload/685022d45d4966ef6ce7eb27ce488ddf.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>"Auth" refers to the authentication system provided by the framework to manage user authentication, including user login, registration, password reset, and session management.</p>
<p>The "Auth" system in Laravel is based on guards and providers. Here’s a breakdown of how it's used:</p>
<ol>
<li><p><strong>Configuration</strong>: Laravel's authentication system is configured primarily in the <code>config/auth.php</code> file. This file defines various settings related to authentication, including different "guards" and "providers".</p>
</li>
<li><p><strong>Guards</strong>: Guards define how users are authenticated for each request. Laravel ships with several guard implementations, including session and token guards. The session guard, for example, maintains user authentication state using session storage.</p>
</li>
<li><p><strong>Providers</strong>: Providers define how users are retrieved from your persistent storage (such as a database). Laravel supports various types of authentication providers, such as Eloquent (for database-based authentication using the ORM) and LDAP (for LDAP authentication).</p>
</li>
<li><p><strong>Usage</strong>: To use the authentication system in your application, you typically interact with it through the <code>Auth</code> facade provided by Laravel. Here are some common operations:</p>
<ul>
<li><p><strong>User Authentication</strong>: To authenticate a user, you can use:</p>
<pre><code class="lang-php">  <span class="hljs-keyword">if</span> (Auth::attempt([<span class="hljs-string">'email'</span> =&gt; $email, <span class="hljs-string">'password'</span> =&gt; $password])) {
      <span class="hljs-comment">// Authentication was successful</span>
  }
</code></pre>
</li>
<li><p><strong>Checking Authentication</strong>: To check if a user is authenticated:</p>
<pre><code class="lang-php">  <span class="hljs-keyword">if</span> (Auth::check()) {
      <span class="hljs-comment">// User is authenticated</span>
  }
</code></pre>
</li>
<li><p><strong>Getting the Authenticated User</strong>: To retrieve the currently authenticated user:</p>
<pre><code class="lang-php">  $user = Auth::user();
</code></pre>
</li>
<li><p><strong>Logging Users Out</strong>: To log out a user:</p>
<pre><code class="lang-php">  Auth::logout();
</code></pre>
</li>
<li><p><strong>Protecting Routes</strong>: Laravel provides route middleware to protect routes from unauthenticated access. You can apply middleware like <code>auth</code> to routes or controllers to enforce authentication:</p>
<pre><code class="lang-php">  Route::get(<span class="hljs-string">'/profile'</span>, <span class="hljs-string">'ProfileController@show'</span>)-&gt;middleware(<span class="hljs-string">'auth'</span>);
</code></pre>
</li>
</ul>
</li>
<li><p><strong>Customization</strong>: Laravel’s authentication system can be customized extensively to fit your application's needs. You can define custom guards and providers in the configuration file (<code>config/auth.php</code>) and extend the existing authentication controllers and services.</p>
</li>
</ol>
]]></content:encoded></item></channel></rss>