<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad Kareem</title>
    <description>The latest articles on DEV Community by Mohammad Kareem (@mohammed_kareem).</description>
    <link>https://dev.to/mohammed_kareem</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1928347%2Ff7882b54-927b-4c79-b8b0-d9f42d8b60ae.png</url>
      <title>DEV Community: Mohammad Kareem</title>
      <link>https://dev.to/mohammed_kareem</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohammed_kareem"/>
    <language>en</language>
    <item>
      <title>Authorization In Laravel - A Beginner's Guide</title>
      <dc:creator>Mohammad Kareem</dc:creator>
      <pubDate>Thu, 12 Sep 2024 22:50:43 +0000</pubDate>
      <link>https://dev.to/mohammed_kareem/authorization-in-laravel-a-beginners-guide-32kf</link>
      <guid>https://dev.to/mohammed_kareem/authorization-in-laravel-a-beginners-guide-32kf</guid>
      <description>&lt;h2&gt;
  
  
  Mastering Authorization in Laravel: Gates vs. Policy Classes 🚪🔐
&lt;/h2&gt;

&lt;p&gt;In a modern web application, controlling who can access or modify resources is crucial. For instance, in a blog application, you might want to ensure that only the owner of a post can edit or delete it. Laravel offers two elegant ways to handle authorization: &lt;strong&gt;Gates&lt;/strong&gt; and &lt;strong&gt;Policy Classes&lt;/strong&gt;. This guide will walk you through both methods, showing you how to protect your resources and ensure your application’s security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gates in Laravel 🚪
&lt;/h2&gt;

&lt;p&gt;Gates provide a quick and straightforward way to handle authorization using closures. They are perfect for simple authorization checks and are defined in the &lt;code&gt;AuthServiceProvider&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up a Gate
&lt;/h3&gt;

&lt;p&gt;Let’s define a gate to ensure that only the post owner can update or delete a post:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Define the Gate&lt;/strong&gt;: Open &lt;code&gt;AuthServiceProvider&lt;/code&gt; and add your gate definitions:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Providers/AuthServiceProvider.php&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Support\Facades\Gate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Models\Post&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;boot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;registerPolicies&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nc"&gt;Gate&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'update-post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nc"&gt;Gate&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'delete-post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Applying the Gate&lt;/strong&gt;: Use the gate in your controller methods to enforce the authorization logic:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Http/Controllers/PostController.php&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Support\Facades\Gate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Models\Post&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Gate&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;denies&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'update-post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'You do not own this post. 🚫'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Proceed with updating the post&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;destroy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Gate&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;denies&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'delete-post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'You do not own this post. 🚫'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Proceed with deleting the post&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Pros and Cons of Gates
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity&lt;/strong&gt;: Quick to set up with minimal code. ⚡&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ideal for Simplicity&lt;/strong&gt;: Perfect for single-resource applications or straightforward scenarios. 📝&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Can become cumbersome and difficult to manage as your application grows. 📈&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintenance&lt;/strong&gt;: May become messy if not well-organized. 🧩&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best Use Case&lt;/strong&gt;: Small applications or simple use cases where a quick authorization check is needed. 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  Policy Classes in Laravel 🛡️
&lt;/h2&gt;

&lt;p&gt;Policy Classes offer a more structured and scalable approach to handling authorization. They provide a clear way to manage complex authorization rules and keep your code organized. Policies are particularly useful when working with resource controllers that include the standard CRUD operations: &lt;strong&gt;index&lt;/strong&gt;, &lt;strong&gt;create&lt;/strong&gt;, &lt;strong&gt;edit&lt;/strong&gt;, &lt;strong&gt;update&lt;/strong&gt;, and &lt;strong&gt;destroy&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating and Using a Policy
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Generate the Policy&lt;/strong&gt;: Create a policy class using Artisan:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:policy PostPolicy
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Define Policy Methods&lt;/strong&gt;: Open the generated policy class and add methods to handle authorization for each action:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Policies/PostPolicy.php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Policies&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Models\User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Models\Post&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostPolicy&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/**
     * Determine if the user can view the list of posts.
     *
     * @param User $user
     * @return bool
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;viewAny&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Example logic to allow viewing posts for authenticated users&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cd"&gt;/**
     * Determine if the user can create a post.
     *
     * @param User $user
     * @return bool
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cd"&gt;/**
     * Determine if the user can update the post.
     *
     * @param User $user
     * @param Post $post
     * @return bool
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cd"&gt;/**
     * Determine if the user can delete the post.
     *
     * @param User $user
     * @param Post $post
     * @return bool
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Using the Policy&lt;/strong&gt;: Apply the policy methods in your controller actions:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Http/Controllers/PostController.php&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Models\Post&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;authorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'update'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Proceed with updating the post&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;destroy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;authorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'delete'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Proceed with deleting the post&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Pros and Cons of Policy Classes
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Organization&lt;/strong&gt;: Provides a clean and organized way to handle complex authorization logic. 📂&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainability&lt;/strong&gt;: Easier to manage and maintain as the application grows. 🛠️&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Framework Support&lt;/strong&gt;: Leverages Laravel’s built-in framework support for consistent authorization. 🔧&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Initial Setup&lt;/strong&gt;: Slightly more setup compared to gates. ⚙️&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complexity&lt;/strong&gt;: May be overkill for very simple authorization scenarios. 🎢&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best Case Scenario&lt;/strong&gt;: Ideal for applications with complex authorization requirements or when aiming for clean, maintainable code. 🌟&lt;/p&gt;




&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Both Gates and Policy Classes in Laravel offer powerful ways to handle authorization. Gates are excellent for quick, simple checks, while Policy Classes provide a structured approach for managing complex scenarios, especially in resource controllers with methods like &lt;strong&gt;index&lt;/strong&gt;, &lt;strong&gt;create&lt;/strong&gt;, &lt;strong&gt;edit&lt;/strong&gt;, &lt;strong&gt;update&lt;/strong&gt;, and &lt;strong&gt;destroy&lt;/strong&gt;. Choose the method that best fits your application’s needs and enjoy a secure, well-organized codebase! 🚀🔐&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>laravel</category>
      <category>security</category>
    </item>
    <item>
      <title>🎉 Celebrating the Launch of Justablog: New Features &amp; Exciting Updates! 🚀</title>
      <dc:creator>Mohammad Kareem</dc:creator>
      <pubDate>Tue, 03 Sep 2024 20:49:06 +0000</pubDate>
      <link>https://dev.to/mohammed_kareem/celebrating-the-launch-of-justablog-new-features-exciting-updates-bl3</link>
      <guid>https://dev.to/mohammed_kareem/celebrating-the-launch-of-justablog-new-features-exciting-updates-bl3</guid>
      <description>&lt;p&gt;Hello fellow nerds! 🌟&lt;/p&gt;

&lt;p&gt;I’m overjoyed to announce the launch of &lt;strong&gt;Justablog&lt;/strong&gt;, my latest Laravel-powered microblogging platform! This project has been a labor of love, and I’m excited to share it with you all. To top it off, we’ve just rolled out some amazing new features that will enhance your experience!&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 What is Justablog?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Justablog&lt;/strong&gt; is a modern microblogging platform designed to offer a sleek, user-friendly experience while providing powerful functionality. Built with Laravel and styled using Tailwind CSS, it’s a space for sharing stories, engaging with content, and connecting with others.&lt;/p&gt;

&lt;h2&gt;
  
  
  🛠️ Key Features of Justablog
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;✨ User Authentication: Effortlessly register, log in, and manage your profile.&lt;/li&gt;
&lt;li&gt;    📝 Post Creation: Create and publish posts with ease.&lt;/li&gt;
&lt;li&gt;    💬 Comments: Engage in conversations directly on posts.&lt;/li&gt;
&lt;li&gt;    ❤️ Likes: Show appreciation with a simple like button.&lt;/li&gt;
&lt;li&gt;    🌑 Dark Mode: Enjoy a sleek dark mode interface.&lt;/li&gt;
&lt;li&gt;    📱 Responsive Design: A design that looks great on any device.&lt;/li&gt;
&lt;li&gt;    🔍 Search Functionality: Find posts quickly by title.&lt;/li&gt;
&lt;li&gt;    👥 Follow/Unfollow System: Keep track of your favorite content creators&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🌟 New Features
&lt;/h2&gt;

&lt;p&gt;We’ve recently introduced some fantastic features that I’m particularly excited about:&lt;/p&gt;

&lt;h3&gt;
  
  
  🔹 &lt;strong&gt;User Profiles&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Customize your profile to make it truly yours! With new options for profile pictures, cover photos, and bios, you can express your unique personality and make a memorable impression. 🖼️🎨&lt;/p&gt;

&lt;h3&gt;
  
  
  🔹 &lt;strong&gt;Follow/Unfollow System&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Stay updated with your favorite users and easily manage your connections with our new follow/unfollow feature. This allows you to curate your feed and stay connected with the content that matters most to you. 🌟🔄&lt;/p&gt;

&lt;h2&gt;
  
  
  📂 Explore Justablog on GitHub!
&lt;/h2&gt;

&lt;p&gt;Interested in exploring the code, contributing, or just taking a closer look? Check out the Justablog repository on GitHub:&lt;/p&gt;

&lt;p&gt;🔗 &lt;a href="https://github.com/EngMohammedKareem/justablog" rel="noopener noreferrer"&gt;Justablog on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to dive into the code, report issues, or suggest features. I’d love to hear your feedback and see how you might contribute to making Justablog even better!&lt;/p&gt;

&lt;h2&gt;
  
  
  🙌 Get Involved
&lt;/h2&gt;

&lt;p&gt;Your support is invaluable! Here’s how you can help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Contribute to Development&lt;/strong&gt;: Browse the codebase and help us improve Justablog.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provide Feedback&lt;/strong&gt;: Share your thoughts and suggestions on the new features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spread the Word&lt;/strong&gt;: Let your network know about Justablog and invite others to join our growing community!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding and blogging! 🚀💪&lt;/p&gt;

</description>
      <category>sideprojects</category>
      <category>php</category>
      <category>laravel</category>
      <category>github</category>
    </item>
    <item>
      <title>Baby Steps Learning Laravel</title>
      <dc:creator>Mohammad Kareem</dc:creator>
      <pubDate>Fri, 30 Aug 2024 18:31:04 +0000</pubDate>
      <link>https://dev.to/mohammed_kareem/baby-steps-learning-laravel-2bn1</link>
      <guid>https://dev.to/mohammed_kareem/baby-steps-learning-laravel-2bn1</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back, Devs! ✨
&lt;/h2&gt;

&lt;p&gt;In this chapter of our Laravel journey (remember, I’m learning as I write these articles, so this will be one of the most realistic tutorial series you can find!), we’ll dive into our Laravel project. We’ll explore the project structure, get familiar with migrations, and break down the MVC architecture in the simplest way possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  📅 Today’s Agenda:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Exploring Our Project Structure&lt;/strong&gt; 🗂️&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand the directory layout and navigate through it smoothly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Setting Up a Database &amp;amp; Learning About Migrations&lt;/strong&gt; 🛠️&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configure our database and get to grips with migrations.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Understanding MVC &amp;amp; Creating Some MVC Elements&lt;/strong&gt; 🔄&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn how the MVC architecture works and tinker with migrations.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  So, What Are All These Directories Doing? 🤔
&lt;/h2&gt;

&lt;p&gt;Upon your first launch of VSCode in your newly created Laravel project, you might find the directory structure a bit intimidating. Here's a quick overview of what each key directory does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;app/&lt;/strong&gt;: Contains application logic (controllers, models).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;resources/views/&lt;/strong&gt;: Where your Blade templates live.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;routes/&lt;/strong&gt;: Contains route definitions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;config/&lt;/strong&gt;: Configuration files for various aspects of Laravel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;database/&lt;/strong&gt;: Migrations, seeders, and SQLite database (if used).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;public/&lt;/strong&gt;: Entry point for web requests, including assets like CSS and JS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Good News&lt;/strong&gt;: You don’t need to know everything right now. Keep this cheatsheet handy!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bad News&lt;/strong&gt;: You'll need to learn about these as the series progresses. I'll add "knowledge checkpoints" to remind you of their purposes. &lt;/p&gt;

&lt;h2&gt;
  
  
  Viewing Your Web App in the Browser 🌐
&lt;/h2&gt;

&lt;p&gt;Let’s get a taste of Laravel! Open your terminal and type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, head over to your browser and visit &lt;code&gt;localhost:8000&lt;/code&gt;. You should see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8yeqy7mqr0jhacqzcy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8yeqy7mqr0jhacqzcy9.png" alt="Image description" width="800" height="521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;: Ensure your server and DB are running (if using XAMPP, as explained in my previous article).&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Artisan? 🔧
&lt;/h2&gt;

&lt;p&gt;If you're used to JavaScript, think of &lt;code&gt;php artisan serve&lt;/code&gt; as similar to &lt;code&gt;npm run dev&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Artisan&lt;/strong&gt; is a powerful command-line tool that comes with Laravel, making various tasks easy and quick. The &lt;code&gt;serve&lt;/code&gt; command starts a local development server. We'll use Artisan more as we progress, so don’t worry too much about it right now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Our Database 💾
&lt;/h2&gt;

&lt;p&gt;A web app is essentially a wrapper for a database. Laravel supports various databases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SQLite&lt;/strong&gt;: Default, zero configuration—ideal for small to medium projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MySQL&lt;/strong&gt;: For larger projects, though SQLite will work for most cases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Setting Up SQLite
&lt;/h3&gt;

&lt;p&gt;You don’t need to configure it; it’s the default database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up MySQL (if using XAMPP)
&lt;/h3&gt;

&lt;p&gt;Edit your &lt;code&gt;.env&lt;/code&gt; file to uncomment the MySQL configuration:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQLite Config&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnctba1xbxyorcxn5rxuk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnctba1xbxyorcxn5rxuk.png" alt="Image description" width="331" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MySQL Config&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd98loozrm700razkzj9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd98loozrm700razkzj9i.png" alt="Image description" width="288" height="121"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;.env&lt;/code&gt; file is like a switchboard for toggling configurations on and off.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Sneak Peek into MVC: Baby Examples 🍼
&lt;/h2&gt;

&lt;p&gt;Before diving deeper into MVC in future articles, let’s get a quick overview with some baby examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is MVC? 🤔
&lt;/h3&gt;

&lt;p&gt;MVC stands for &lt;strong&gt;Model-View-Controller&lt;/strong&gt;. It’s a design pattern that separates concerns in your application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model&lt;/strong&gt;: 🗃️ Manages the data and business logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;View&lt;/strong&gt;: 👁️ Displays data to the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Controller&lt;/strong&gt;: 🎛️ Connects the Model and View, handling input and data flow.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠️ Baby Example: A Simple "Hello World" App
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Model&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Here’s a &lt;code&gt;Greeting&lt;/code&gt; model for storing messages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Models/Greeting.php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Models&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Database\Eloquent\Model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Greeting&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'greetings'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$fillable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. &lt;strong&gt;View&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The view displays the greeting message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- resources/views/greeting.blade.php --&amp;gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Greeting&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;{{ $message }}&amp;lt;/h1&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. &lt;strong&gt;Controller&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The controller fetches the greeting message and passes it to the view:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Http/Controllers/GreetingController.php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Http\Controllers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Models\Greeting&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GreetingController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Controller&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Greeting&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'greeting'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$greeting&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model&lt;/strong&gt;: Manages data (&lt;code&gt;Greeting&lt;/code&gt; class).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;View&lt;/strong&gt;: Presents data (&lt;code&gt;greeting.blade.php&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Controller&lt;/strong&gt;: Connects Model and View (&lt;code&gt;GreetingController&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Model&lt;/strong&gt; handles the data.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;View&lt;/strong&gt; presents the data.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Controller&lt;/strong&gt; connects the two.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In future articles, we'll dive deeper into each component and explore more complex examples. Stay tuned! 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>laravel</category>
      <category>sideprojects</category>
    </item>
    <item>
      <title>Setting Up A Development Environment For Laravel</title>
      <dc:creator>Mohammad Kareem</dc:creator>
      <pubDate>Wed, 28 Aug 2024 17:46:10 +0000</pubDate>
      <link>https://dev.to/mohammed_kareem/setting-up-a-development-environment-for-laravel-115b</link>
      <guid>https://dev.to/mohammed_kareem/setting-up-a-development-environment-for-laravel-115b</guid>
      <description>&lt;h1&gt;
  
  
  🚀 &lt;strong&gt;Setting Up Your Laravel Development Environment on Windows&lt;/strong&gt; 🖥️
&lt;/h1&gt;

&lt;p&gt;Hey Devs! 👋&lt;/p&gt;

&lt;p&gt;Welcome to my new series where I’ll be diving into the world of Laravel! 🎉 As I’m learning Laravel myself, I’m excited to share the knowledge and insights I’ve gathered so far. My goal is to help you break into Laravel development smoothly and efficiently. 🌟&lt;/p&gt;

&lt;p&gt;I believe in the power of shared learning, so this series will not only guide you through the setup but also evolve over time. I might revisit and improve upon the content based on new discoveries or feedback. Who knows? We might uncover even better practices together! 🚀&lt;/p&gt;

&lt;p&gt;The end goal of this series is to build a beautiful job board where users could submit job postings, it's packed with features and will cover many key concepts like MVC architecture, authentication, authorization, policies, styling and templating and more!!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4boosh7r8c63g71cirki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4boosh7r8c63g71cirki.png" alt="Image description" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifq91ayhnij0un2c13wp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifq91ayhnij0un2c13wp.png" alt="Image description" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With all that being said it's time to dive into the world of Laravel on a Windows machine, Whether you're starting fresh or setting up a new project, this guide will walk you through the essentials of getting your Laravel development environment up and running. Let’s get started! 😎&lt;/p&gt;

&lt;h2&gt;
  
  
  🌟 But why Choose Laravel?
&lt;/h2&gt;

&lt;p&gt;Laravel is your gateway to rapid, robust, and modern web development. 🚀 Here's why it’s a game-changer:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Elegant Syntax:&lt;/strong&gt; Laravel’s syntax is clean and expressive, making coding a joy and boosting productivity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Built-in Tools:&lt;/strong&gt; From authentication and routing to caching and sessions, Laravel comes with a suite of tools that save you time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Active Community:&lt;/strong&gt; Laravel boasts a vibrant community and extensive documentation, so help is always at your fingertips.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scalability &amp;amp; Security:&lt;/strong&gt; Laravel provides powerful features to scale your apps and keep them secure.&lt;/p&gt;

&lt;p&gt;In a nutshell, Laravel empowers you to build high-quality applications quickly and efficiently. Why wait? Dive in and see the magic for yourself! 🌟 ( literal black magic, the framework is just that inelegant and knows what the dev wants )&lt;/p&gt;

&lt;h2&gt;
  
  
  1. 🛠️ &lt;strong&gt;Download and Install XAMPP&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;XAMPP is your go-to solution for setting up a local server environment. It includes Apache, MySQL, and PHP—all the goodies you need to run Laravel.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Download XAMPP:&lt;/strong&gt; Head over to &lt;a href="https://www.apachefriends.org/index.html" rel="noopener noreferrer"&gt;XAMPP’s official website&lt;/a&gt; and grab the latest version for Windows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Install XAMPP:&lt;/strong&gt; Run the installer and follow the prompts. Make sure Apache and MySQL are selected during installation as these are crucial for Laravel.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. 📦 &lt;strong&gt;Install Composer&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Composer is a powerful dependency manager for PHP that Laravel relies on. Here’s how to get it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Download Composer:&lt;/strong&gt; Visit &lt;a href="https://getcomposer.org/" rel="noopener noreferrer"&gt;Composer’s website&lt;/a&gt; and download the Composer-Setup.exe file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Install Composer:&lt;/strong&gt; Run the installer and follow the instructions. During setup, ensure that the installer finds the PHP executable from your XAMPP installation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. 🚀 &lt;strong&gt;Create a New Laravel Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now that you have XAMPP and Composer ready, it’s time to create your Laravel project!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Open Command Prompt:&lt;/strong&gt; Navigate to where you want to create your Laravel project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run Composer Command:&lt;/strong&gt; Execute the following command to create a new Laravel project:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  composer create-project laravel/laravel my-laravel-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;my-laravel-app&lt;/code&gt; with your desired project name ( job-board in our case )&lt;/p&gt;

&lt;h2&gt;
  
  
  4. 🌟 &lt;strong&gt;Setting Up Your Environment&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once your Laravel project is created, you’ll need to configure a few things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Navigate to Your Project Directory:&lt;/strong&gt; Use &lt;code&gt;cd my-laravel-app&lt;/code&gt; to go into your project directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run Laravel Development Server:&lt;/strong&gt; Start the built-in Laravel server by running:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  php artisan serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start a local development server at &lt;code&gt;http://127.0.0.1:8000&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;quick note: make sure that your server and db are running by pressing start on your xampp control panel for your server and db&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frg7qcr2t8rm1oowjy0dg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frg7qcr2t8rm1oowjy0dg.png" alt="Image description" width="665" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. 🔄 &lt;strong&gt;Additional Tips&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Database Configuration:&lt;/strong&gt; Open &lt;code&gt;.env&lt;/code&gt; in your Laravel project and configure your database settings to match your MySQL setup in XAMPP.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check Dependencies:&lt;/strong&gt; Regularly update your project’s dependencies by running &lt;code&gt;composer update&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🎉 &lt;strong&gt;You’re All Set!&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Congratulations! 🎊 You’ve successfully set up a Laravel development environment on Windows. Now you're ready to start building amazing applications! &lt;/p&gt;

&lt;p&gt;Feel free to drop any questions or share your experiences in the comments. &lt;br&gt;
Happy coding! 💻🚀&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>php</category>
      <category>laravel</category>
    </item>
    <item>
      <title>🚀 Introducing Ticketly: A Simple Ticketing System Built with Laravel 🎟️</title>
      <dc:creator>Mohammad Kareem</dc:creator>
      <pubDate>Mon, 26 Aug 2024 14:23:40 +0000</pubDate>
      <link>https://dev.to/mohammed_kareem/introducing-ticketly-a-simple-ticketing-system-built-with-laravel-371n</link>
      <guid>https://dev.to/mohammed_kareem/introducing-ticketly-a-simple-ticketing-system-built-with-laravel-371n</guid>
      <description>&lt;p&gt;Hey DEV Community! 👋&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpv9c2zsjrurj0vp18bua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpv9c2zsjrurj0vp18bua.png" alt="Image description" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxotftlg88yoodmf6im0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxotftlg88yoodmf6im0.png" alt="Image description" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0rqugoqamd4tv96mhrrf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0rqugoqamd4tv96mhrrf.png" alt="Image description" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbohasj4k8ty490ngrumd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbohasj4k8ty490ngrumd.png" alt="Image description" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m thrilled to share my latest project: Ticketly – a straightforward yet powerful ticketing system built with Laravel. This has been an incredible learning experience and a chance to dive deep into Laravel and modern web development tools. 🌟&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Ticketly?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ticketly is a web application designed to streamline the management of support tickets within an organization. It features functionalities for both regular users and administrators, making ticket management efficient and user-friendly.&lt;br&gt;
Key Features&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For Employees / Regular Users:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Create new tickets&lt;/li&gt;
&lt;li&gt;View and manage their own tickets&lt;/li&gt;
&lt;li&gt;Delete their own tickets&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;For Administrators:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Update ticket statuses&lt;/li&gt;
&lt;li&gt;Open&lt;/li&gt;
&lt;li&gt;Processing&lt;/li&gt;
&lt;li&gt;Closed&lt;/li&gt;
&lt;li&gt;An email notification is sent when an admin updates or deletes a ticket&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tech Stack&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Backend &amp;amp; Frontend: Laravel (Blade Templating Engine)&lt;/li&gt;
&lt;li&gt;    Database: MySQL&lt;/li&gt;
&lt;li&gt;    Authentication: Laravel Breeze&lt;/li&gt;
&lt;li&gt;    Styling: Tailwind CSS&lt;/li&gt;
&lt;li&gt;    Email: Mailtrap (for testing)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This project allowed me to explore several key Laravel features and concepts, including:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Routing &amp;amp; Controllers: Handling HTTP requests and application logic.&lt;/li&gt;
&lt;li&gt;    Authentication: Implementing user authentication with Laravel Breeze.&lt;/li&gt;
&lt;li&gt;    Authorization: Managing access with policies and middleware.&lt;/li&gt;
&lt;li&gt;    Eloquent ORM: Interacting with the database using Eloquent.&lt;/li&gt;
&lt;li&gt;    Blade Templating: Building dynamic views with Blade.&lt;/li&gt;
&lt;li&gt;    Tailwind CSS: Creating modern, responsive designs with utility-first CSS.&lt;/li&gt;
&lt;li&gt;    Email Notifications: Sending notifications using Mailtrap.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Highlight: Filter by Priority&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the exciting features implemented is the ability to filter tickets by priority. This functionality allows users to view tickets based on their urgency, improving support ticket management and resolution efficiency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explore the Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can check out the project and its codebase on &lt;a href="https://github.com/EngMohammedKareem/Ticketly/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. I’m excited to hear your feedback and suggestions!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Future Plans&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd like to take the opportunity to announce an upcoming series on my blog here to teach you guys Laravel in order to be able to build similar projects and even better projects so stay tuned for episode 1!&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;#Laravel #WebDevelopment #OpenSource #TicketingSystem #PHP #MySQL #TailwindCSS #EmailNotifications #Coding #Programming #DevCommunity&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learn Enough Regex Without Losing Your Mind</title>
      <dc:creator>Mohammad Kareem</dc:creator>
      <pubDate>Sat, 17 Aug 2024 09:37:48 +0000</pubDate>
      <link>https://dev.to/mohammed_kareem/learn-enough-regex-without-losing-your-mind-2lap</link>
      <guid>https://dev.to/mohammed_kareem/learn-enough-regex-without-losing-your-mind-2lap</guid>
      <description>&lt;p&gt;I fully understand that Regex is such a complex and borderline witchcraft topic to the average dev ( myself included ) but trust me it's extremely powerful and can solve issues in some cases so i decided to put together this simple blog to try my best to teach you enough regex without losing your mind :) &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REGEX BASICS FOR THE CURIOUS OF SOUL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So to be completely transparent with you if i could write 20 lines of code in order to avoid writing a regex i'd do it BUT it's still useful in some use cases and tbh a valid solution so let's learn the basics and enough to work with regex&lt;/p&gt;

&lt;p&gt;&lt;em&gt;this blog will be programming language agnostic as i won't use any as an example but stick to the syntax itself rather than using it in a programming language&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WHAT IS REGEX AND WHY DO I NEED IT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Regex is text pattern matching that helps us match pieces of text according to a pattern we specify using special operators, so arranging those regex operators in a way to do any text processing task you could imagine&lt;/p&gt;

&lt;p&gt;Examples include : email validation, phone number validation, postal code validation, credit card validation, etc etc……&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HOW CAN I PRACTISE MY REGEX ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;we’re gonna use &lt;a href="https://www.debuggex.com/" rel="noopener noreferrer"&gt;this online tool&lt;/a&gt; to help us test and visualize our regex in real time, it’s an amazingly great tool to learn since we can see our mistakes as well as finding out why such pattern worked&lt;/p&gt;

&lt;p&gt;We’re gonna build few examples to learn as much regex as we need to start and it’ll be just enough for now until we run into super complex stuff&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    phone number example&lt;/li&gt;
&lt;li&gt;    email example&lt;/li&gt;
&lt;li&gt;    price tag example&lt;/li&gt;
&lt;li&gt;    DD/MM/YYYY date format example&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;OUR CHEATSHEET FOR THIS TUTORIAL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To stay focused we're gonna cover these operators as i believe they're more than enough to wrap your head around regex but it goes without saying that regex can get pretty complicated but we're only interested in pretty basic pattern matching stuff so here's our little cheatsheet :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;    ^ beginning of a line&lt;/li&gt;
&lt;li&gt;    $ end of the line&lt;/li&gt;
&lt;li&gt;    [] grouping — basically means “ranges” like [a-z], [0–9]&lt;/li&gt;
&lt;li&gt;    {} means how many times you’d like this pattern to occur&lt;/li&gt;
&lt;li&gt;    ? one or zero times aka optional operator&lt;/li&gt;
&lt;li&gt;    + at least one or more times, basically means i don’t care how many time this pattern occurs&lt;/li&gt;
&lt;li&gt;    * zero or more times&lt;/li&gt;
&lt;li&gt;    \w will match every letter, number and underscore&lt;/li&gt;
&lt;li&gt;    \d will match single digits only&lt;/li&gt;
&lt;li&gt;    \s space&lt;/li&gt;
&lt;li&gt;    \t tab&lt;/li&gt;
&lt;li&gt;    / escape special characters — in case we wanna match an actual dollar sign for example&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;REGEX HELLO WORLD&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So the most basic regex we can write is the text itself ! suppose you wanna extract a name for example “Bridget”, you can literally write Bridget so let’s jump to our online tool and find out&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42odzjuiz7r4jw7ipaqr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42odzjuiz7r4jw7ipaqr.png" alt="regex hello world" width="800" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;USING MORE OPERATORS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4hk2xd3dg6ltzikphy0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4hk2xd3dg6ltzikphy0.png" alt="using more operators" width="800" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don’t panic 😄 there’s nothing fancy going on at all there, so our pattern now says “start the line, find Bridget, close the line”, as discussed earlier the carrot ^ means the line begins with……everything that follows and the $ means the end of the line, so again, find me this pattern where the line starts with the word Bridget and the line ends&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INTRODUCING GROUPS TO MATCH MORE PATTERNS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;OK so now our regex only matches this one word…..but what if we wanna match more ? We’re not gonna write every name are we 😂&lt;/p&gt;

&lt;p&gt;For that we’re gonna use the square brackets to use grouping, which means find me a pattern that consist of this group of letters or numbers or special characters, so let’s write a regex that simply matches any given first name then we’ll extend it to include more words separated by spaces basically to simulate a full name&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi7r94n6hhu00bo23dbh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi7r94n6hhu00bo23dbh.png" alt="full name example" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now pay attention to the visualization and how we now have two “blocks” basically, it simply says, find me this pattern where there is a small or a capital letter infinitely followed by a space followed by the same pattern for the block prior&lt;/p&gt;

&lt;p&gt;&lt;em&gt;quick note, English is my second language so my explanation can be a little misunderstood or inaccurate so please pardon me, I’ll try to explain as simple as possible and provide visuals&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;USING REGEX TO VALIDATE A US PHONE NUMBER&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we know some regex let’s try to validate a phone number, so a US phone number consists of 3-digit area code followed by another 3 digits that represent a central office, followed by 4digits that represent the subscriber number so it should look like 202–555–0160 ( a fake number btw ) and we’ll include the dashes too&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftofvbyfyu87lmtqdzyui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftofvbyfyu87lmtqdzyui.png" alt="phone number validation" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See how easy it is now :) isn’t regex so much fun so far 😍, notice how we simply added the dashes as they don’t represent anything in regex so they’re treated literally as they look, you notice how we so far “draw” how our data should look like ? I really hope it clicked :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EMAIL VALIDATION USING REGEX&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we’re gonna do a classic regex which is validating an email address but bear in mind that this is pretty basic as i imagine real production level regex patterns will be far more complex but we’re just tinkering around for fun :)&lt;/p&gt;

&lt;p&gt;This example will demonstrate how can we add more than just numbers and letters to our group&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzr5iqt07vhm6t2qaepqe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzr5iqt07vhm6t2qaepqe.png" alt="email validation" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EXTRACTING A PRICE FROM A WEBPAGE WITH REGEX&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ok now a more fun example ( hopefully so ) so let's say you're scraping amazon or whatever website and you needed to extract a price for something, well regex makes this extremely easy plus we'll get to learn about character escaping since $ is already a regex operator&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1ca581dpe28zq3wp01p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1ca581dpe28zq3wp01p.png" alt="price validation using regex" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;translation is: it begins with a digit (0-9) followed by a dot ( yes we had to escape that too ) followed by another number and lastly a dollar sign &lt;/p&gt;

&lt;p&gt;But you'll notice that our regex only applies to prices with a floating point aka not whole numbers like 14$ so how do we fix that ? &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;USING THE ? OPERATOR TO INDICATE THE OPTIONAL PRESENCE OF A PATTERN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To address the mentioned issue above well use the ? operator to signal to our regex expression that the second half of the price is optional in case we run into whole numbers so let's quickly fix our regex &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx8bha8kltbg2ttzrwnb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx8bha8kltbg2ttzrwnb.png" alt="idek anymore" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FINAL NOTES&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As in anything software related, you NEED to practise more to the point where the concept becomes natural to you and a thing of a habit so use the online tool i mentioned above and you can always learn more and if you find yourself in need to learn more regex then go for it cause the best way to learn something besides practise is to actually use the new knowledge in solving your own issues &lt;/p&gt;

&lt;p&gt;Thank you so much if you've made it this far and i pray to God i can always bring you the most useful of content and be able to give back to the online community that made me who i am today &lt;/p&gt;

</description>
      <category>regex</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>.Env Files For Tech Noobs</title>
      <dc:creator>Mohammad Kareem</dc:creator>
      <pubDate>Wed, 14 Aug 2024 20:10:20 +0000</pubDate>
      <link>https://dev.to/mohammed_kareem/env-files-for-tech-noobs-2g37</link>
      <guid>https://dev.to/mohammed_kareem/env-files-for-tech-noobs-2g37</guid>
      <description>&lt;p&gt;When deploying your web app / project online, the last thing you’d want is to have sensitive information leaked such as some auth tokens or api keys etc etc&lt;br&gt;
So this begs the question : how can i secure sensitive data my program needs ?&lt;br&gt;
This blog will explore environment variables, what are they ? when do i need them ? how can i create them ? how do i use them ? &lt;/p&gt;
&lt;h2&gt;
  
  
  ENVIRONMENT VARIABLE 101
&lt;/h2&gt;

&lt;p&gt;Now as well know we use variables all the time when we are writing any piece of software, variables are just boxes to store pieces of data inside but still wth is an environment variable ? &lt;/p&gt;

&lt;p&gt;Environment variables are essentially variables required needed by your environment ( duh lmao ) aka your operating system&lt;/p&gt;

&lt;p&gt;Think of them as "switches" or basically pieces of configuration your system needs to behave accordingly &lt;/p&gt;

&lt;p&gt;An example of an environment variable is PATH on Windows which essentially informs the OS where the executables at&lt;/p&gt;

&lt;p&gt;And yes you can easily create your own environment variables rn rn &lt;/p&gt;
&lt;h2&gt;
  
  
  TIME TO CREATE SOME ENVIRONMENT VARIABLES FELLAS
&lt;/h2&gt;

&lt;p&gt;Ok so let's see how to set up our own environment variables (drinking game for how many times i typed that LMAO ) on Windows which is actually pretty simple so please lads pop up cmd with admin privileges and type along&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setx MY_CAT "simsim"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So what's happening here ? Well the syntax is simple, we use &lt;code&gt;setx&lt;/code&gt; to set environment variables followed by our variable name which is preferably in all uppercase then we specify the value ( yes i have a cat named simsim ;) )&lt;/p&gt;

&lt;p&gt;Now to print out our newly created env var ( yes i'm sick of typing it out ) we simply say&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo %MY_CAT%&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  In the context of web development / programming
&lt;/h2&gt;

&lt;p&gt;Now that we've established the basic idea behind env vars it's time to actually use them and see why would we need them in our projects&lt;/p&gt;

&lt;p&gt;Often times your project will reach out to external APIs and web services, those service providers need those tokens / API tokens to verify who's consuming their API as well as implement some rate limiting or such, in addition to those you might have your database credentials / s3 credentials / etc, and trust me you don't want any of these to be leaked by accident &lt;/p&gt;

&lt;p&gt;This is where environment variables come into play, we create a file named .env and we store those important credentials in it and then we can access them in our code regardless of your project tech stack, this stuff just works like that &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SO JEFF LEAKED HIS DISCORD BOT TOKEN 😱&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So in this imaginary ( yet very much possible ) scenario we'll have a look at our dear friend Jeff and how did he make a terrible mistake cause he didn't know about the magic of environment variables &lt;/p&gt;

&lt;p&gt;So let’s say Jeff has just built the sickest discord bot built with cutting edge technology and powered by the finest AI models.....to tell the weather using node.js and he’s excited to show it off on his github&lt;/p&gt;

&lt;p&gt;But few hours later……. the bot doesn’t return the current weather as it should, hmmm quite odd isn’t it? Jeff goes to the api provider website to check his dashboard and see how much of daily quota he used and……..IT’S GONE BUT HOW DID IT HAPPEN&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SO HOW TO NOT BE LIKE JEFF&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Trust me you don’t wanna be like Jeff, you’ve got to protect your api keys or auth tokens or any piece of authentication info that should only be used by YOU and ONLY YOU so how do we do that ?&lt;/p&gt;

&lt;p&gt;In this example we’ll assume we’re building some node.js app because you can’t really hide your credentials on the front end, all it takes is checking the network tab and you can see the request headers and bam you’re screwed ( real )&lt;/p&gt;

&lt;p&gt;Now let's create our &lt;code&gt;.env&lt;/code&gt; file and see how do we store those tokens and stuff&lt;/p&gt;

&lt;p&gt;I will use node.js as an example despite being a Laravel lover&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API_KEY="SUPER SECRET API KEY"
CONSUMER_KEY="some other stuff here"
OTHER_VERY_SECRET_TOKEN="blah blah"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the syntax is pretty simple, BUT REMEMBER the variable name is very very preferred to be in all uppercase and don't leave any space before and after the = sign&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ACCESSING THOSE VARIABLES IN OUR CODE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now back to our sick discord bot project that'll be acquired by Elon Musk, so now that we've set up our environment variables it's time to actually use them in our project right ? Well in node.js that's pretty simple all you gotta do is install a package named &lt;code&gt;dotenv&lt;/code&gt; because for some reason only God knows, &lt;code&gt;process.env&lt;/code&gt; doesn't just work out of the box so let's do that now&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i dotenv --dev&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Now in our node.js program let's just slap this bad boy in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require('dotenv').config();
let api_key = process.env.API_KWY;
let api_key = process.env['API_KEY']; // same shit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and voila ✨ you're now a full stack web dev ( kidding ) &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EXTRA LAYER OF SECURITY FOR THE GIT NERDS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As we all know you're not a real FAANG material until you use a version control utility ( mostly Git ) and if you're worked with Git before you'd know that it's a piece of software to enable to push your project entirely to Github or Gitlab to allow collaborations with other interested devs&lt;/p&gt;

&lt;p&gt;Now this begs the question &lt;em&gt;if i'm sharing my project files with the world including but not limited to.....my env file am i not gonna end up like Jeff ?&lt;/em&gt; and to answer your question...yes pretty much &lt;/p&gt;

&lt;p&gt;To prevent you from being Jeff'ed let's talk about something called ✨&lt;code&gt;.gitignore&lt;/code&gt;✨ files and don't be intimidated by how vague that looks&lt;/p&gt;

&lt;p&gt;So what is that, you might ask ? Well a &lt;code&gt;.gitignore&lt;/code&gt; tells your version control to ignore the mentioned files inside it ( no shit ) &lt;/p&gt;

&lt;p&gt;Now create one and paste this in &lt;/p&gt;

&lt;p&gt;&lt;code&gt;.env&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Yea fellas that's pretty much it, always store sensitive data in your &lt;code&gt;.env&lt;/code&gt; file and don't forget to include it in your &lt;code&gt;.gitignore&lt;/code&gt; file if you're using Git for version control &lt;/p&gt;

&lt;p&gt;Thanks a lot for making it this far and i am excited to share more web dev / tech content with you on Dev.to since i migrated from Medium so expect more content coming so soon PLUS original content ofc focused entirely on Laravel and as always have a lovely $PART_OF_THE_DAY &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>computerscience</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
