<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Sule-Balogun Olanrewaju - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Sule-Balogun Olanrewaju - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 18 May 2026 22:34:21 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/suleolanrewaju/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Write a Good Conference Talk Proposal – CFP Guide ]]>
                </title>
                <description>
                    <![CDATA[ When conferences organize events, they seek knowledgeable speakers to share insights that educate, inspire, and engage attendees. They discover and select speakers through a Call for Proposals (CFP), an open invitation for experts to submit talk idea... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-write-a-good-conference-talk-proposal/</link>
                <guid isPermaLink="false">68079cde283b1638560a2135</guid>
                
                    <category>
                        <![CDATA[ conference ]]>
                    </category>
                
                    <category>
                        <![CDATA[ speaking  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Tue, 22 Apr 2025 13:42:54 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1745329255973/f4fbb77f-8cab-4c29-bdd0-2791037bc6fd.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When conferences organize events, they seek knowledgeable speakers to share insights that educate, inspire, and engage attendees. They discover and select speakers through a Call for Proposals (CFP), an open invitation for experts to submit talk ideas. A well-crafted CFP submission can be the difference between being selected to speak or getting lost in a sea of applications.</p>
<p>Conferences offer different session formats, such as lightning talks, workshops, panels, and full-length sessions. Organizers look for clear, relevant, and valuable topics for their audience. A strong proposal aligns with the event's topic and clearly demonstrates its significance to reviewers.</p>
<p>I have been selected to speak at conferences such as API World, API Specification Conference, PyCon Italia, and PHP Day Italy, and I co-organize API Conf Lagos. From both sides of the table, when submitting and reviewing CFPs, I have seen what works and what does not.</p>
<p>In this guide, I’d like to share what makes a good CFP and offer tips on creating a standout proposal. Whether you are submitting for the first time or looking to refine your approach, these insights will help you craft a compelling proposal that gets noticed.</p>
<p>In this article, you’ll learn the following:</p>
<ul>
<li><p><a class="post-section-overview" href="#understanding-the-cfp-criteria">Understanding the CFP Criteria</a></p>
</li>
<li><p><a class="post-section-overview" href="#key-components-of-a-cfp-submission">Key Components of a CFP Submission</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-choose-the-right-topic-theme">How to Choose the Right Topic</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-craft-a-strong-title-and-abstract">How to Craft a Strong Title and Abstract</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-structure-the-proposal">How to Structure the Proposal</a></p>
</li>
<li><p><a class="post-section-overview" href="#submission-best-practices">Submission Best Practices</a></p>
</li>
<li><p><a class="post-section-overview" href="#where-to-find-cfp-opportunities">Where to Find CFP Opportunities</a></p>
</li>
</ul>
<h2 id="heading-understanding-the-cfp-criteria">Understanding the CFP Criteria</h2>
<p>CFP requirements vary from conference to conference, so understanding the specific criteria before submitting your application is crucial to increasing your chances of selection. Most conferences provide a criteria page outlining key details. When you’re writing a CFP submission, some criteria are more crucial than others in shaping a strong proposal.</p>
<p>The most relevant criteria include:</p>
<ul>
<li><p><strong>Topic</strong> – Areas of interest that the conference aims to cover.</p>
</li>
<li><p><strong>Session format and duration</strong> – This indicates the available sessions for the conference. It could be a session, workshop, or lightning talk, along with the time allocated.</p>
</li>
<li><p><strong>Audience expectations</strong> – This is used to gauge the audience's level of expertise (beginner, intermediate, advanced) and what attendees hope to gain from the event.</p>
</li>
</ul>
<p>Keeping an eye on the core criteria, topic, audience, and format will help ensure your CFP submission aligns well with the conference expectations. And this can help increase your chances of acceptance.</p>
<p>While necessary for planning, other logistical aspects play a less direct role in crafting the proposal. These include:</p>
<ul>
<li><p><strong>Speaker logistics and support</strong> – Information on travel, accommodation, and benefits for speakers, such as honorariums or reimbursements.</p>
</li>
<li><p><strong>Event fees and scholarships</strong> – Whether speakers receive free entry or if financial aid options are available.</p>
</li>
<li><p><strong>Code of conduct</strong> – The conference sets the ethical and behavioral guidelines for speakers and attendees.</p>
</li>
<li><p><strong>Conference duration</strong> – Whether the event lasts for one day, two days, or multiple days, which may affect scheduling and availability.</p>
</li>
</ul>
<h2 id="heading-elements-of-a-cfp">Elements of a CFP</h2>
<h3 id="heading-talk-title">Talk Title</h3>
<p>First, you’ll need to decide on a clear, compelling title that makes it obvious what the talk is about in an easy-to-understand way. Clarity and simplicity always win.</p>
<p>You should avoid overly verbose or clickbait-style titles like: <em>“Harnessing the Ultimate</em> <em>Power of Next-Gen APIs to Revolutionize Your Tech Stack”</em>. Instead, you could say something friendlier and clearer: <em>“How to Design Scalable APIs That Align With Your Product.”</em></p>
<h3 id="heading-abstract">Abstract</h3>
<p>The abstract is a brief description of your talk. In this section, you should provide a summary that generally explains what your talk is about, how the audience would benefit from it, and why the conference organizers should value and select your talk.</p>
<p>It’s acceptable to discuss example scenarios you plan to cover and the tools or libraries you’ll be using, as this will help promote your idea more effectively than a simple sentence or two with no technical info.</p>
<h3 id="heading-detailed-descriptionproposal">Detailed Description/Proposal</h3>
<p>I would like to note that not all conferences offer this section, but for those that do, it is a more in-depth and detailed explanation of your abstract, which sometimes can exceed 1000 words. This will enable you to explain the value, structure, areas of focus, and key takeaways of your talk.</p>
<p>In both the abstract and proposal, you should discuss the problems you’re addressing in your talk and what the audience stands to learn, which are both very important.</p>
<h3 id="heading-speaker-bio">Speaker Bio</h3>
<p>This is just as important as the talk title itself, as it informs the organizers about who you are, where you work, your relevant experience, and how the conference can benefit from having you at the event. Include a recent picture of yourself and, if possible, provide your social media profiles like LinkedIn, so they can connect with you.</p>
<p>Alright, now that you know the various parts involved in creating a CFP, let's look at each component in more detail – and how you can actually craft each part.</p>
<h2 id="heading-how-to-choose-the-right-topic">How to Choose the Right Topic</h2>
<p>Most CFP pages showcase topics that interest conference organizers. As a prospective speaker, your goal is to select a topic that aligns with these subjects. You’ll also want to make sure that you have a deep enough knowledge on the topic you choose to speak and answer questions about it confidently.</p>
<p>For example, if a conference emphasizes specific topics such as PHP, Continuous Delivery, DevOps, Security, Testing, or APIs, proposals that align with those subjects are more likely to be accepted. Submitting a topic outside the listed themes the conference plans to cover may reduce your chances unless it provides exceptional value to the audience.</p>
<p>Here are some practical examples:</p>
<ul>
<li><p>If a conference is focused on <strong>DevOps</strong>, your proposal is more likely to be accepted if it covers continuous delivery pipelines, performance and monitoring, infrastructure automation, or incident response practices. Submitting a topic outside the listed subject, such as frontend design, may reduce your chances unless it offers exceptional value to the audience.</p>
</li>
<li><p>If a conference is focused on <strong>APIs</strong>, your proposal is more likely to be accepted if it covers how to design versioned APIs, securing API endpoints with Authentication and Authorization, scaling API-first applications, compliance and governance, Api performance and observability, Api documentation, or managing third-party integrations.</p>
</li>
<li><p>For a PHP conference, you should submit a proposal that cover performance improvements in PHP 8+, real-world security use cases in Laravel applications such as OWASP, PHP architecture patterns, scaling large PHP applications, writing extensions in PHP, highlighting important libraries you use daily, or guiding attendees on how to contribute to such PHP libraries.</p>
</li>
</ul>
<p>When selecting your topics, ask yourself:</p>
<ul>
<li><p>What’s the value I’m bringing to attendees?</p>
</li>
<li><p>Is the topic something I’m passionate about and knowledgeable about?</p>
</li>
<li><p>Does it align with the needs and interests of the target audience?</p>
</li>
</ul>
<p>To improve your chances, tailor your proposal to fit the conference’s focus. Pay close attention to the wording of your topic and ensure it directly connects with the event’s goals.</p>
<h2 id="heading-how-to-craft-a-strong-title-and-abstract">How to Craft a Strong Title and Abstract</h2>
<p>Once you've chosen a relevant topic, you’ll need to create your talk title and abstract. For instance, you might focus on addressing security concerns using a particular programming language or tackle modern security challenges within a niche area.</p>
<p>It’s important to remember that while tools like AI models (for example, ChatGPT) can be helpful, relying too heavily on them to craft your title and abstract can work against you. The key is to use clear, simple language that speaks directly to your audience. Avoid overly technical jargon or convoluted phrasing, as this may hinder understanding.</p>
<p>Here are some key things to keep in mind when choosing a title and writing your abstract:</p>
<h3 id="heading-select-a-friendly-title"><strong>Select a Friendly Title</strong></h3>
<p>Your title is the first thing conference organizers see, and keeping it simple, engaging, and clear should be the goal.</p>
<p>Examples of strong titles might include:</p>
<ul>
<li><p>Moving Beyond CRUD: Designing More Scalable APIs with TDD</p>
</li>
<li><p>How to Keep Your Application Secure with the Zero Trust Principle</p>
</li>
<li><p>Why You Should Care About the Risk and Rewards of Feature Flags</p>
</li>
<li><p>How to Orchestrate Effective Releases with CI/CD with Practical Tips for Teams</p>
</li>
</ul>
<p>You may be wondering why these are examples of strong titles. Well, it’s because:</p>
<ul>
<li><p>They are clear and accessible, and at a glance, you already know what the topic is about. The topics are also approachable even if you’re not an expert.</p>
</li>
<li><p>The topics also highlight values or possible outcomes: either the audience will learn about risk and rewards with feature flags, or they will equip themselves with knowledge of securing their applications using the Zero Trust principle, or learn how to design scalable APIs in a test-driven manner.</p>
</li>
<li><p>The topic targets those directly involved in the software delivery lifecycle, including developers, DevOps engineers, engineering teams, and managers.</p>
</li>
</ul>
<h3 id="heading-writing-a-compelling-abstract"><strong>Writing a Compelling Abstract</strong></h3>
<p>When writing your abstract, it’s essential to provide a thorough overview of what your talk will cover. A one or two-sentence summary likely won’t be enough to give conference organizers the deeper insight they need into what your session offers.</p>
<p>Your abstract expands on the talk title, providing a more detailed description of the topic. This includes what your talk will cover (if it’s a workshop, mention the language or tools used, along with any expected outcomes or builds), the attendees who would benefit most from the talk, and possible learning outcomes.</p>
<p>Spending most of your time crafting your abstract is crucial to your talk getting accepted. From experience, here’s what a good abstract should include:</p>
<ul>
<li><p>Start with a sentence or two introducing the subject. So if you’re talking about the Zero-trust principle, explain what it means and discuss why it matters. Then talk about the problem it helps stakeholders involved in software delivery solve.</p>
</li>
<li><p>Describe what the talk will cover. Mention tools, frameworks, or case studies you’ll use here to deliver the talk if selected. For example, “We’ll cover core concepts like 'Never trust, always verify,' least privilege, and continuous monitoring, along with practical steps such as using OAuth2, MFA, RBAC, JWTs, and encryption”.</p>
</li>
<li><p>Explain who the target audience is. Are they beginners, intermediates, or experts? This will help organizers place your talk on the right track for the identified audience.</p>
</li>
<li><p>End your abstract with 2-3 clear learning outcomes. What will attendees be able to do, understand, or think differently about after your session? For example, attendees will learn about Zero Trust architecture, enforcing strong authentication and authorization, as well as tools for continuous monitoring and auditing to detect threats.</p>
</li>
</ul>
<p>Don’t rush through the process of writing your abstract. Allow yourself time to develop it gradually as ideas come to mind. It’s perfectly fine to keep your proposal open and pinned, updating and refining it over time. This approach will give you the bandwidth to ensure your abstract is clear, comprehensive, and engaging, ultimately leading to a stronger proposal.</p>
<p>Remember, your abstract should be written in simple, clear language and be free from grammatical errors. Keep in mind that some conferences have word limits for abstracts, so ensure your description fits these constraints.</p>
<h2 id="heading-how-to-structure-the-proposal">How to Structure the Proposal</h2>
<p>Once you’ve identified a topic and written the abstract, it’s crucial to structure your proposal in a way that is easy to read and provides clarity regarding your target audience and the learning outcomes. A well-structured proposal makes it easier for conference organizers to understand the value of your session and decide whether it’s a good fit.</p>
<p>To illustrate this, we’ll look at two proposal examples: one that can be improved and one with a strong structure that’s likely to be accepted.</p>
<h4 id="heading-weaker-proposal">❌ Weaker Proposal</h4>
<p><strong>Topic</strong>: Security in Software Development</p>
<p><strong>Abstract</strong>:<br>Security in software development is important. This session will cover security practices and techniques in code.</p>
<p><em>Why this proposal is weak</em>:</p>
<ul>
<li><p>The title is too vague and doesn’t specify the talk's focus.</p>
</li>
<li><p>The abstract lacks depth and does not clearly describe what the attendees will learn.</p>
</li>
<li><p>The audience is unclear, and no specific learning outcomes are mentioned.</p>
</li>
</ul>
<h4 id="heading-strong-proposal">✅ <strong>Strong Proposal</strong></h4>
<p><strong>Topic</strong>: Building Secure Web Applications with Modern [Programming Language 1] Frameworks</p>
<p><strong>Abstract</strong>:</p>
<p>It’s important to think security first when trying to build applications for the web, regardless of what programming language or framework you’re using. In today’s world, securing your application will protect you from data breaches, prevent fraudulent transactions, and help you avoid common vulnerabilities, ultimately improving the performance of your system.</p>
<p>In this talk, we will discuss the key security practices that developers should follow when building web applications with modern JavaScript frameworks, such as [Framework 1] and [Framework 2]. We’ll cover concepts such as input validation, securing APIs, handling authentication, and best practices to prevent common security vulnerabilities, including cross-site scripting (XSS) and SQL injection.</p>
<p>At the end of this session, developers will gain actionable insights on implementing security measures, explore common vulnerabilities, and build a demo app using [Framework 1] or [Framework 2] to address the security concept listed above, along with secure coding practices and tools to safeguard their apps.</p>
<p>This talk is designed for intermediate and advanced JavaScript developers who want to enhance the security of their web applications.</p>
<p><em>Why this proposal is strong</em>:</p>
<ul>
<li><p>The title is clear and specific, highlighting the session's main focus.</p>
</li>
<li><p>The abstract provides an introduction, a detailed description of the content that will be covered, ensuring organizers know exactly what to expect.</p>
</li>
<li><p>The target audience is defined as "intermediate and advanced JavaScript developers."</p>
</li>
<li><p>Learning outcomes are clearly outlined, including actionable takeaways and specific skills attendees will gain.</p>
</li>
</ul>
<p>Here are two samples of my proposals that have been accepted in the past.</p>
<ul>
<li><p>PHPDAY ITALY ‘25: <a target="_blank" href="https://www.phpday.it/talks_speakers/#Securing-PHP-Applications-with-Zero-Trust-Principles">Securing PHP Applications with Zero Trust Principles</a></p>
</li>
<li><p>API SPECIFICATION CONFERENCE ‘21: <a target="_blank" href="https://apispecs21.sched.com/event/lMMS/abc-of-graphql-alabi-deborah-sule-balogun-olanrewaju-g">ABC of GRAPHQL</a></p>
</li>
</ul>
<h2 id="heading-submission-best-practices">Submission Best Practices</h2>
<p>Once you've completed your proposal, it's essential to take a step back and reflect on your topic and abstract. Review your submission carefully for any areas that need refining, check for typos, and ensure the message is clear and well-structured.</p>
<p>Sometimes, sharing your proposal with colleagues or peers for feedback can be invaluable. They might catch things you overlooked or offer suggestions to improve clarity or focus.</p>
<p>This reflection and review process acts as a safety net, ensuring you haven’t missed anything important before submitting. Keep in mind that conference organizers receive hundreds of CFPs, so taking the extra time to polish your submission can significantly improve your chances of standing out in a competitive pool.</p>
<p>The submission process typically looks like this:</p>
<h3 id="heading-1-call-for-paper-cfp-announcement">1. Call for Paper (CFP) Announcement</h3>
<p>The conference announces its call for papers (CFP) information, including details such as the deadline, topics, venue, session types, and submission guidelines.</p>
<h3 id="heading-2-submission-platform">2. Submission Platform</h3>
<p>Conferences use tools like Typeform, Sessionize, Papercall, and even Google Docs, based on preference, and you’ll be asked to provide information about your talk proposal. This information includes:</p>
<ul>
<li><p>Talk title</p>
</li>
<li><p>Abstract</p>
</li>
<li><p>Talk format (Workshop, Session, Keynote)</p>
</li>
<li><p>Target audience</p>
</li>
<li><p>Speaker bio</p>
</li>
<li><p>[Optional] Past speaking experience, like YouTube links to previous talks, and so on</p>
</li>
</ul>
<h3 id="heading-review-phase">Review Phase</h3>
<p>After the CFP closes, panels begin reviewing submissions and deciding who will speak at the conference. They select speakers based on their own checklist and determine the lineup of speakers.</p>
<h3 id="heading-notification-and-follow-up">Notification and Follow-up</h3>
<p>Successful speakers will receive congratulatory emails notifying them to confirm their participation in the conference and may need to submit additional information, such as a slide deck or session outline.</p>
<p>Speakers who don’t make the cut will typically get a rejection email, and often some organizers extend free or discounted event tickets to those speakers who have invested their time in submitting a proposal.</p>
<h3 id="heading-conference-schedule">Conference schedule</h3>
<p>Once selected, speakers will have their bio, talk title, and abstract published on the conference website. The schedule will also include the date, time, and room where each session will take place, helping attendees plan which talks to attend.</p>
<h2 id="heading-where-to-find-cfp-opportunities">Where to Find CFP Opportunities</h2>
<p>If you're looking for conferences to submit your proposal to, several platforms and resources regularly list open calls for papers (CFPs). Instead of waiting to stumble upon a CFP announcement, you can actively search for speaking opportunities that align with your expertise.</p>
<h3 id="heading-popular-cfp-platforms">Popular CFP Platforms:</h3>
<ul>
<li><p><a target="_blank" href="https://sessionize.com/"><strong>Sessionize</strong></a> – A widely used platform where conferences post CFPs, allowing speakers to submit proposals easily.</p>
</li>
<li><p><a target="_blank" href="https://www.papercall.io/"><strong>PaperCall.io</strong></a> – A hub for discovering CFPs across different industries, including tech and open-source events.</p>
</li>
</ul>
<h3 id="heading-other-ways-to-discover-cfps">Other Ways to Discover CFPs:</h3>
<ul>
<li><p><strong>Conference websites</strong>: Many conferences post their CFPs directly under a "Call for Papers" or "Call for Speakers" section.</p>
</li>
<li><p><strong>Tech communities and newsletters:</strong> Platforms like Dev.to, Hashnode, and newsletters often share open CFPs.</p>
</li>
<li><p><strong>Social media</strong>: Following conference organizers and speakers on LinkedIn and Twitter can help you stay updated about new CFP openings.</p>
</li>
<li><p><strong>Local and virtual meetups</strong>: Many meetup groups are seeking speakers, and these smaller events can be a great way to gain experience before applying to larger conferences.</p>
</li>
</ul>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>In this article, you learned what makes a good conference talk proposal, how to structure your proposal with examples, and submission best practices.</p>
<p>Keep improving your proposal, and good luck with your submissions!</p>
<p>You can find me on <a target="_blank" href="https://www.linkedin.com/in/suleolanrewaju/">LinkedIn</a> and <a target="_blank" href="https://twitter.com/bigdevlarry">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a Linked list? Types of Linked List with Code Examples ]]>
                </title>
                <description>
                    <![CDATA[ A linked list is a linear data structure consisting of a sequence of nodes. Unlike arrays, linked lists do not require contiguous memory allocation. Instead, each node is dynamically allocated its own memory space.  Nodes are connected through refere... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-linked-list-types-and-examples/</link>
                <guid isPermaLink="false">66ba2fe64d935175898a7086</guid>
                
                    <category>
                        <![CDATA[ data structures ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Mon, 18 Mar 2024 15:25:17 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/03/john-petter-fagerhaug-nlT3NvhGKt8-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A linked list is a linear data structure consisting of a sequence of nodes. Unlike arrays, linked lists do not require contiguous memory allocation. Instead, each node is dynamically allocated its own memory space. </p>
<p>Nodes are connected through references, forming the linked structure. One advantage of linked lists is that insertion and deletion of elements at the beginning of the list can be done in constant time, denoted as O(1). </p>
<p>This efficiency stems from the ability to directly manipulate references without needing to shift elements as required in arrays. Data types in a linked list can be any of the available data types supported by a programming language.</p>
<p>In this tutorial, you'll learn the following:</p>
<ul>
  <li><a href="#understanding-linked-list">Understanding Linked list</a></li>
  <li><a href="#types-of-linked-list">Types of Linked List</a></li>
    <li><a href="#summary-of-operations">Summary of operations with their respective time and space complexities in tabular format.</a></li>
  <li><a href="#differentiate-between-array-and-linked-list">Differences Between Array and Linked list.</a></li>
  <li><a href="#how-to-solve-the-remove-duplicates-from-sorted-list-problem">Algorithm: Solve the Remove Duplicates from Sorted list in PHP and JavaScript.</a></li>
</ul>

<h2 id="understanding-linked-list"> Understanding Linked list </h2>

<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/Untitled-2024-01-31-1554.png" alt="Untitled-2024-01-31-1554" width="600" height="400" loading="lazy"></p>
<p>head =&gt; Points to the first box in the list<br>tail =&gt; Points to the last box in the list</p>
<p>To access the data in the first box</p>
<p>head.data =&gt; 6</p>
<p>To access the data in the second box, we first need to set the pointer (arrow) to point to the box. Hence we need the (next)<br>head.next =&gt; This points to the next item on the list<br>head.next.data =&gt; 4</p>
<p>To access the data in the third box, we first need to set the pointer (arrow) to point to the box. Hence we need the (next.next)<br>head.next.next =&gt; This points to the next &gt; next item on the list<br>head.next.next.data =&gt; 5</p>
<h3 id="heading-what-is-a-node">What is a node ?</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/node.png" alt="node" width="600" height="400" loading="lazy"></p>
<p>A node in a linked list is an example of a self-referential structure in programming. This structure is comprised of elements called nodes, where each node contains both data and a reference to another node of the same type. This reference, often termed a 'pointer,' facilitates the creation of a chain-like structure, where nodes are interconnected, forming the linked list.</p>
<p>The self-referential nature of nodes allows for efficient traversal and manipulation of data within the linked list. The structure can be implemented using classes or arrays</p>
<h3 id="heading-how-to-implement-a-linked-list-using-classes">How to Implement a Linked List Using classes</h3>
<pre><code class="lang-php"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Node</span> </span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params">
        <span class="hljs-keyword">public</span> $data,
        <span class="hljs-keyword">public</span> ?Node $next = <span class="hljs-literal">null</span>
    </span>) </span>{}
}

<span class="hljs-comment">// Creating nodes</span>

$node1 = <span class="hljs-keyword">new</span> Node(<span class="hljs-number">10</span>);
$node2 = <span class="hljs-keyword">new</span> Node(<span class="hljs-number">20</span>);
$node3 = <span class="hljs-keyword">new</span> Node(<span class="hljs-number">30</span>);

<span class="hljs-comment">// Linking nodes</span>

$node1-&gt;next = $node2;
$node2-&gt;next = $node3;

<span class="hljs-comment">// Traversing linked list</span>

$current = $node1;
<span class="hljs-keyword">while</span> ($current != <span class="hljs-literal">null</span>) {
    <span class="hljs-keyword">echo</span> $current-&gt;data . <span class="hljs-string">" "</span>;
    $current = $current-&gt;next;
}
</code></pre>
<h3 id="heading-how-to-implement-a-linked-list-using-using-arrays">How to Implement a Linked List Using Using arrays</h3>
<pre><code class="lang-php"><span class="hljs-comment">// creating nodes as an associative array</span>

$node1 = [<span class="hljs-string">'data'</span> =&gt; <span class="hljs-number">10</span>, <span class="hljs-string">'next'</span> =&gt; <span class="hljs-literal">null</span>];
$node2 = [<span class="hljs-string">'data'</span> =&gt; <span class="hljs-number">20</span>, <span class="hljs-string">'next'</span> =&gt; <span class="hljs-literal">null</span>];
$node3 = [<span class="hljs-string">'data'</span> =&gt; <span class="hljs-number">30</span>, <span class="hljs-string">'next'</span> =&gt; <span class="hljs-literal">null</span>];

<span class="hljs-comment">// linking nodes</span>

$node1[<span class="hljs-string">'next'</span>] = &amp;$node2;
$node2[<span class="hljs-string">'next'</span>] = &amp;$node3;

<span class="hljs-comment">// Traversing linked list</span>

$current = $node1;
<span class="hljs-keyword">while</span> ($current != <span class="hljs-literal">null</span>) {
  <span class="hljs-keyword">echo</span> $current[<span class="hljs-string">"data"</span>] . <span class="hljs-string">" "</span>;
  $current = &amp;$current[<span class="hljs-string">"next"</span>];
}
</code></pre>
<p>In both cases, we create a structure where each element (node) contains data and a reference (next) to another element of the same type. This creates a self-referential structure. We then link these elements together to form a data structure like a linked list. Finally, we traverse the structure to access and manipulate its elements.</p>
<p>Unlike an array, a linked list doesn't provide constant time access to a particular index within the list. This means that if you'd like to find the nth element in the list, you'll need to traverse through to the nth element. </p>
<p>Traversing a linked list means iterating through each node of the list until the end node is reached.</p>
<h2 id="types-of-linked-list"> Types of Linked list</h2>

<p>We'll discuss the types under the Traversal, Memory and Complexity categories.</p>
<h2 id="heading-singly-linked-list">Singly Linked List</h2>
<p>Each node has data and a reference to the next node. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/singly-2.png" alt="singly linked list" width="600" height="400" loading="lazy"></p>
<h3 id="heading-non-code-explanation">Non-code explanation</h3>
<p>Imagine taking a journey by train, where each train represents a part of your trip, and each station represents a point where you need to make a change.</p>
<ul>
<li>Train A represents the first part of your journey, taking you from Station A to Station B. When you arrive at Station B, there's a sign directing you to switch trains to continue your journey.</li>
<li>Train B represents the second part of your journey, taking you from Station B to Station C. Again, when you arrive at Station C, there's no sign for another train because you've reached your final destination.</li>
</ul>
<p>In this analogy:</p>
<ul>
<li>Each train segment (Train A, Train B, and Train C) represent a node in the singly linked list.</li>
<li>The task of each train is analogous to the data stored in each node, representing a segment of your journey.</li>
<li>The transition between trains at each station is analogous to the "next" pointer in a linked list, indicating the next segment of your journey.</li>
<li>At the final destination (Station C), there's no need for a pointer or sign to another train because it's the end of your journey.</li>
</ul>
<p>In simpler terms, a singly linked list is like a train journey with different segments, where each train (node) has the task of taking you from one station to the next until you reach your final destination. The transitions between trains are like pointers, guiding you through each segment of your journey.</p>
<h3 id="heading-performance-characteristics-of-singly-linked-list">Performance Characteristics of Singly Linked List</h3>
<ol>
<li><strong>Traversal:</strong> Traversal is allowed only in one direction (that is, forward only). You can move forward through the list, but you cannot easily move backward. </li>
<li><strong>Memory Efficiency:</strong> Singly linked list is generally more memory-efficient because it requires only one reference per node. </li>
<li><strong>Complexity:</strong> Insertion and Deletion operation is easier as you only need to update references in one direction.</li>
</ol>
<h3 id="heading-time-and-space-complexity">Time and Space Complexity</h3>
<p>I wrote about constant and linear time complexity <a target="_blank" href="https://www.freecodecamp.org/news/what-is-a-hash-map/">here</a>, and we'll be using that to discuss the general time and space complexities for some common operations:</p>
<h4 id="heading-traversal">Traversal</h4>
<p>Time complexity O(n), where n is the number of nodes in the list. Space complexity O(1), it doesn't require additional space proportional to the input size.</p>
<h4 id="heading-insertion-at-the-beginning">Insertion at the Beginning</h4>
<p>Time complexity O(1), it involves updating references at the head. Space complexity O(1), it doesn't require additional space proportional to the input size.</p>
<h4 id="heading-insertion-at-the-end">Insertion at the End</h4>
<p>Time complexity O(n), it may require traversing the entire list to reach the end. Space complexity O(1), it doesn't require additional space proportional to the input size.</p>
<h4 id="heading-deletion-at-the-beginning">Deletion at the Beginning</h4>
<p>Time complexity O(1), it involves updating references at the head. Space complexity O(1), constant.</p>
<h4 id="heading-deletion-at-the-end">Deletion at the End</h4>
<p>Time complexity O(n), it may require traversing the entire list to reach the end. Space complexity O(1), constant.</p>
<h2 id="heading-doubly-linked-list">Doubly Linked List</h2>
<p>In a doubly linked list, the <code>head</code> node typically does not have a <code>prev</code> reference because it is the first node and therefore has no previous node. </p>
<p>However, the <code>head</code> node does have a <code>next</code> reference pointing to the next node in the list. Each node has data and references to both the next and previous nodes.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/doubly-1.png" alt="doubly-1inked-list" width="600" height="400" loading="lazy"></p>
<h3 id="heading-non-code-explanation-1">Non-code explanation</h3>
<p>Imagine that you have a book where each page represents a task you need to complete, just like items on your to-do list.</p>
<p>Each page does not only contain information about the task written on it but also has connections to the pages before and after it in the book.</p>
<ul>
<li>Page 1 (Task A) represents the first task in the book. It contains information about Task A and has an arrow pointing forward to Page 2 (Task B), indicating that Task B comes after Task A in the book. However, Page 1 does not have a backward arrow because it is the first page of the book and doesn't have a previous page.</li>
<li>Page 2 (Task B) contains information about Task B and has arrows pointing both forward to Page 3 (Task C) and backward to Page 1 (Task A), indicating that Task C comes after Task B and Task A comes before Task B in the book.</li>
<li>Page 3 (Task C) represents the last task in the book. It contains information about Task C and has an arrow pointing backward to Page 2 (Task B), indicating that Task B comes before Task C in the book.</li>
</ul>
<p>With this in mind, you can think of a doubly linked list as a book where each page not only contains information about a task but also provides easy navigation to the tasks before and after it. The first page, similar to the head of a doubly linked list, does not have a previous reference, while the last page, similar to the tail of a doubly linked list, does not have a next reference</p>
<h3 id="heading-performance-characteristics-of-doubly-linked-lists">Performance Characteristics of Doubly Linked Lists</h3>
<ol>
<li><strong>Traversal:</strong> Doubly linked lists allow traversal in both directions — forward and backward. This bidirectional traversal enables more flexible navigation through the list, allowing operations such as iterating in reverse order.</li>
<li><strong>Memory Efficiency</strong>: Doubly linked lists typically require more memory compared to singly linked lists because each node contains two references (pointers) — one for the next node and one for the previous node. This additional memory overhead per node can impact the overall memory efficiency, especially for large lists.</li>
<li><strong>Complexity</strong>: Doubly linked lists offer bidirectional traversal and flexibility. Insertion and deletion operations may require updating references in both directions (forward and backward), which can increase the complexity and potentially impact performance.</li>
</ol>
<h3 id="heading-time-and-space-complexity-1">Time and Space Complexity</h3>
<h4 id="heading-traversal-1">Traversal</h4>
<p>The time and space complexity for this operation is the same with the singly linked list.</p>
<h4 id="heading-insertion-at-the-beginning-1">Insertion at the Beginning</h4>
<p>The time and space complexity for this operation is the same with the singly linked list.</p>
<h4 id="heading-insertion-at-the-end-1">Insertion at the End</h4>
<p>Time complexity for this operation takes O(1) time. This is because you have direct access to the tail node, so you can update the references without needing to traverse the entire list. Space complexity O(1), it doesn't require additional space proportional to the input size.</p>
<h4 id="heading-deletion-at-the-beginning-1">Deletion at the Beginning</h4>
<p>The time and space complexity for this operation is the same with the singly linked list.</p>
<h4 id="heading-deletion-at-the-end-1">Deletion at the End</h4>
<p>Time complexity for this operation takes O(1) time. This is because you have direct access to the tail node, so you can update the references without needing to traverse the entire list. Space complexity O(1), it doesn't require additional space proportional to the input size.</p>
<h2 id="heading-circular-linked-list">Circular Linked List</h2>
<p>A circular linked list is a type of linked list where the last node of the list points back to the first node, forming a circle or loop. This characteristic distinguishes it from a traditional linked list, where the last node typically points to null, indicating the end of the list. In a circular linked list, there is no null pointer at the end; instead, the last node points back to the first node, creating a loop structure. This looping behavior allows for continuous traversal through the list. The below image shows how a singly circular linked list works.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/circular-linked-list-1.png" alt="circular-linked-list-1" width="600" height="400" loading="lazy"></p>
<h3 id="heading-non-code-explanation-2">Non-code explanation</h3>
<p>Imagine a train line that forms a loop, with passengers boarding and exiting at various stations along the way. This loop represents a circular linked list, where each station is a node and the train continuously travels around the loop, picking up and dropping off passengers. </p>
<p>Just like in a circular linked list, the loop ensures continuous traversal without an end point, and passengers (data) can be added or removed at any station (node).  </p>
<p>The circular linked list offers advantages in certain applications but requires careful handling of pointers and memory management to maintain its circular structure and prevent issues such as infinite loops.</p>
<h3 id="heading-performance-characteristics-of-circular-linked-lists">Performance Characteristics of Circular Linked Lists</h3>
<ol>
<li><strong>Traversal:</strong> Circular linked lists enable traversal in a loop, allowing seamless navigation from one node to another regardless of the direction. This circular structure facilitates efficient traversal without needing to iterate back to the beginning when reaching the end, enhancing traversal performance.</li>
<li><strong>Memory Efficiency</strong>: Singly circular linked lists typically offer similar memory efficiency to singly linked lists, as they require only one pointer per node to connect to the next node in the sequence. This single-pointer structure results in lower memory overhead per node compared to doubly linked lists, potentially improving memory efficiency for large lists.</li>
<li><strong>Complexity:</strong> In singly circular linked lists, insertion and deletion operations require updating references to maintain the circular structure, introducing moderate complexity compared to linear linked lists.</li>
</ol>
<h3 id="heading-time-and-space-complexity-2">Time and Space Complexity</h3>
<h4 id="heading-traversal-2">Traversal</h4>
<p>Time Complexity: O(n) – Since you have to traverse through all the nodes in the list to reach the end. </p>
<p>Space Complexity: O(1) – Only a constant amount of extra space is required for a temporary variable to traverse the list.</p>
<h4 id="heading-insertion-at-the-beginning-2">Insertion at the Beginning</h4>
<p>Time Complexity: O(1) – Insertion at the beginning simply involves updating the references at the head. </p>
<p>Space Complexity: O(1) – No additional space is required.</p>
<h4 id="heading-insertion-at-the-end-2">Insertion at the End</h4>
<p>Time Complexity: O(n) – It may require traversing the entire list to reach the end where insertion needs to take place.</p>
<p>Space Complexity: O(1) – No additional space is required.</p>
<h4 id="heading-deletion-at-the-beginning-2">Deletion at the Beginning</h4>
<p>Time complexity O(1), it involves updating references at the head. </p>
<p>Space complexity O(1), constant.</p>
<h4 id="heading-deletion-at-the-end-2">Deletion at the End</h4>
<p>Time complexity O(n), it may require traversing the entire list to reach the end.</p>
<p>Space complexity O(1), constant.</p>
<h2 id="summary-of-operations"> Summary of Operations for the Time Complexity </h2>

<table>
<thead>
<tr>
<th>Operation</th>
<th>Singly Linked List</th>
<th>Doubly Linked List</th>
<th>Circular Linked List</th>
</tr>
</thead>
<tbody>
<tr>
<td>Traversal</td>
<td>O(n)</td>
<td>O(n)</td>
<td>O(n)</td>
</tr>
<tr>
<td>Insertion at Beginning</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Insertion at End</td>
<td>O(n)</td>
<td>O(1)</td>
<td>O(n)</td>
</tr>
<tr>
<td>Deletion at Beginning</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Deletion at End</td>
<td>O(n)</td>
<td>O(1)</td>
<td>O(n)</td>
</tr>
</tbody>
</table>


<h2 id="summary-of-operations"> Summary of Operations for the Space Complexity </h2>

<table>
<thead>
<tr>
<th>Operation</th>
<th>Singly Linked List</th>
<th>Doubly Linked List</th>
<th>Circular Linked List</th>
</tr>
</thead>
<tbody>
<tr>
<td>Traversal</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Insertion at Beginning</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Insertion at End</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Deletion at Beginning</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
<tr>
<td>Deletion at End</td>
<td>O(1)</td>
<td>O(1)</td>
<td>O(1)</td>
</tr>
</tbody>
</table>

<h2 id="differentiate-between-array-and-linked-list"> Differences Between Array and Linked list </h2>

<p>A linked list is a dynamic way to represent a list, where adding and removing items from the beginning of the list typically involves changing only a few pointers. This operation can be performed in constant time, denoted as O(1), regardless of the list's size.</p>
<p>On the other hand, arrays are a sequential representation of a list. Adding or removing items from the beginning of the list requires shifting all subsequent elements to accommodate the change. This operation has a time complexity of O(n), where n is the number of elements in the array. Therefore, for large arrays, adding or removing items from the beginning can be relatively slow compared to linked lists.</p>
<h2 id="how-to-solve-the-remove-duplicates-from-sorted-list-problem"> How to Solve the Remove Duplicates from Sorted List Problem </h2>

<p>Explanation of the problem: Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong></em> as well.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/algo-sample-3.png" alt="algo-sample-3" width="600" height="400" loading="lazy"></p>
<h3 id="heading-solution-in-php">Solution in PHP</h3>
<pre><code class="lang-php"><span class="hljs-comment">/**
 * Definition for a singly-linked list.
 * class ListNode {
 *     public $val = 0;
 *     public $next = null;
 *     function __construct($val = 0, $next = null) {
 *         $this-&gt;val = $val;
 *         $this-&gt;next = $next;
 *     }
 * }
 */</span>


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span> </span>{

    <span class="hljs-comment">/**
     * <span class="hljs-doctag">@param</span> ListNode $head
     * <span class="hljs-doctag">@return</span> ListNode
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">deleteDuplicates</span>(<span class="hljs-params">$head</span>) </span>{
        $node = $head;

        <span class="hljs-keyword">while</span>($node !== <span class="hljs-literal">null</span> &amp;&amp; $node-&gt;next !== <span class="hljs-literal">null</span>) {

            <span class="hljs-keyword">if</span> ($node-&gt;val == $node-&gt;next-&gt;val) {
                $node-&gt;next = $node-&gt;next-&gt;next;
            }<span class="hljs-keyword">else</span> {
                $node = $node-&gt;next;
            }   
        }

        <span class="hljs-keyword">return</span> $head;
    }
}
</code></pre>
<h3 id="heading-solution-in-javascript">Solution in JavaScript</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */</span>
<span class="hljs-comment">/**
 * <span class="hljs-doctag">@param <span class="hljs-type">{ListNode}</span> <span class="hljs-variable">head</span></span>
 * <span class="hljs-doctag">@return <span class="hljs-type">{ListNode}</span></span>
 */</span>


<span class="hljs-keyword">var</span> deleteDuplicates = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">head</span>) </span>{
    <span class="hljs-keyword">let</span> node = head;

    <span class="hljs-keyword">while</span>(node?.next) {

        <span class="hljs-keyword">if</span> (node.val === node.next.val) {
            node.next = node.next.next
        } <span class="hljs-keyword">else</span> {
            node = node.next
        }
    }

    <span class="hljs-keyword">return</span> head
};
</code></pre>
<p><strong>Code explanation</strong></p>
<p>Given the <code>deleteDuplicates</code> method:</p>
<ul>
<li><code>node</code> is initialized to the head of the linked list.</li>
<li>A while loop iterates through the linked list until the end or until the current node's <code>next</code> property is <code>null</code>.</li>
<li>Inside the loop, it checks if the current node's value is equal to the next node's value. If they are equal, it skips the next node by setting the current node's <code>next</code> property to the next node's <code>next</code> property.</li>
<li>If the values are not equal, it moves to the next node by updating the value of <code>node</code> to <code>node-&gt;next</code>.</li>
<li>Finally, the method returns the head of the modified linked list.</li>
</ul>
<p>The null safe operator (<code>?.</code>) used in the JS code solution is also available from PHP 8.0. </p>
<p>This code efficiently removes duplicates from a singly-linked list by adjusting pointers and has a time complexity of <code>_O_(_n_)</code> and a space complexity of <code>_O_(1)</code>, where <em><code>n</code></em> is the number of nodes in the linked list.</p>
<h2 id="heading-reference">Reference</h2>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-linked-lists-work/">How does a linked list work</a></li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, you learned about linked list, types of linked list and a real world problem that involves solving the removal of duplicates from sorted list.</p>
<p>Keep learning, and Happy Coding!</p>
<p>You can find me on <a target="_blank" href="https://www.linkedin.com/in/suleolanrewaju/">LinkedIn</a> and <a target="_blank" href="https://twitter.com/bigdevlarry">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a Hash Map? Time Complexity and Two Sum Example ]]>
                </title>
                <description>
                    <![CDATA[ A hash table or hash map, is a data structure that helps with mapping keys to values for highly efficient operations like the lookup, insertion and deletion operations. In this tutorial, you'll learn the following: Constant and linear time complexit... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-hash-map/</link>
                <guid isPermaLink="false">66ba2fd8de9370f66eeb0aa1</guid>
                
                    <category>
                        <![CDATA[ algorithms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data structures ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Hash tables ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mapping ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Thu, 25 Jan 2024 17:02:13 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/01/joan-gamell-ZS67i1HLllo-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A hash table or hash map, is a data structure that helps with mapping keys to values for highly efficient operations like the lookup, insertion and deletion operations.</p>
<p>In this tutorial, you'll learn the following:</p>
<ul>
<li>Constant and linear time complexity.</li>
<li>Why use a hash map?</li>
<li>Things to consider when writing hash functions.</li>
<li>How to solve the Two Sum problem in PHP and JavaScript.</li>
</ul>
<h2 id="heading-what-is-constant-time-complexity-o1">What is Constant Time Complexity - O(1)?</h2>
<p>O(1) indicates that the running time of an algorithm is constant, regardless of the input size. </p>
<p>This implies that the algorithm's performance isn't dependent on the size of the input. An example is accessing an index of an array.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">constantTimeAlgorithm</span>(<span class="hljs-params">$arr</span>) 
</span>{

    <span class="hljs-keyword">echo</span> $arr[<span class="hljs-number">0</span>] . PHP_EOL;
}
</code></pre>
<p>Here is a non-code example to illustrate the concept of constant time complexity:</p>
<p>Imagine sending a file through an airline to your friend, and the airline has a policy where they charge based on the weight of the package.</p>
<p>Now, whether your file weighs 2 grams or 20 kilograms, the airline's processing time remains constant. This means that the time it takes for the airline to handle your package doesn't depend on the weight of the file – it's always the same. </p>
<p>In other words, the processing time is constant irrespective of the size of the file.</p>
<h2 id="heading-what-is-linear-time-complexity-on">What is Linear Time Complexity - O(n)?</h2>
<p>O(n) indicates that the running time of an algorithm grows linearly with the size of the input. </p>
<p>The performance of the algorithm is directly proportional to the input size. An example is traversing a <code>for</code> loop and printing elements.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">linearTimeAlgorithm</span>(<span class="hljs-params">$arr</span>) 
</span>{
    <span class="hljs-keyword">foreach</span> ($arr <span class="hljs-keyword">as</span> $element) {
        <span class="hljs-keyword">echo</span> $element . PHP_EOL;
    }
}
</code></pre>
<p>Here's a non-code example to illustrate the concept of linear time complexity:</p>
<p>Consider using an electronic transfer service to send a file to your friend. In this scenario, the time it takes to transfer the file increases linearly with the size of the file. </p>
<p>For instance, if it takes 1 minutes to transfer a 100 MB file, it would take approximately 100 minutes to transfer a 10 GB file using the same service. </p>
<p>This linear relationship between the size of the file and the time it takes to transfer it reflects linear time complexity. The time taken to transfer the file increases proportionally or linearly with the size of the input or file.</p>
<h2 id="heading-why-use-a-hash-map">Why use a Hash Map?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/image-108.png" alt="Image" width="600" height="400" loading="lazy">
<em>Illustration of how a hash map works</em></p>
<p>A hash map is a concrete implementation of the abstract data type known as an associative array. </p>
<p>In a hash map, keys are hashed to determine the index where the corresponding values will be stored, allowing for efficient retrieval and storage of key-value pairs. </p>
<p>This implementation typically provides fast access times for operations like insertion, deletion, and lookup of values based on their associated keys. </p>
<p>In languages like PHP or JavaScript, when you use an associative array, you are essentially using a hash map. Their associative arrays are implemented using hash tables behind the scenes. </p>
<p>You can use strings, integers, or other data types as keys, and the language's internal hashing mechanism efficiently maps these keys to their corresponding values. Additionally, JavaScript provides the <code>Map</code> object for more advanced hash map functionalities.</p>
<h3 id="heading-time-and-space-complexity-for-hash-map">Time and Space Complexity for Hash Map</h3>
<p>The time and space complexity for a hash map (or hash table) is not necessarily O(n) for all operations. The typical and desired time complexity for basic operations like insertion, lookup, and deletion in a well-designed hash map is O(1) on average. </p>
<p>Here's a breakdown of time and space complexity for a hash map:</p>
<h4 id="heading-time-complexity">Time Complexity:</h4>
<p>Average Case:</p>
<ul>
<li>Insertion (average): O(1)</li>
<li>Lookup (average): O(1)</li>
<li>Deletion (average): O(1)</li>
</ul>
<p>Worst Case:</p>
<ul>
<li>Insertion (worst): O(n), where n is the size of the hash map. This occurs when there are many hash collisions, leading to linear probing or other collision resolution strategies that may involve traversing the entire hash map.</li>
<li>Lookup and Deletion (worst): O(n), for the same reason as insertion.</li>
</ul>
<h4 id="heading-space-complexity">Space Complexity:</h4>
<ul>
<li>The space complexity is typically O(n). Where n is the number of key-value pairs stored in the hash map. Each key-value pair occupies constant space, and the space required grows linearly with the number of elements.</li>
</ul>
<p>In algorithm analysis, the notation O(1) and O(n) represent the upper bounds on the time complexity of an algorithm, where n is the size of the input.</p>
<h4 id="heading-operations">Operations</h4>
<ol>
<li><strong>Insertion:</strong> The key-value pair is hashed, and the resulting index is used to store the value in the corresponding slot. If a collision occurs, the collision resolution strategy is applied.</li>
<li><strong>Deletion:</strong> The key is hashed to find the index, and the item at that index is removed. Collision resolution may be necessary.</li>
<li><strong>Lookup:</strong> The key is hashed to find the index, and the value at that index is returned. Collision resolution may be applied if needed.</li>
</ol>
<h2 id="heading-things-to-consider-when-creating-hash-tables">Things to consider When Creating Hash Tables</h2>
<p>When creating hash tables, there are several important considerations to ensure efficiency, including fast computation of hash codes and effective collision resolution strategies.</p>
<h3 id="heading-fast-computation">Fast Computation</h3>
<p>Hash codes should be computed quickly to ensure efficient insertion, lookup, and deletion operations. A good hash function contributes to the speed of hash code computation.</p>
<h3 id="heading-avoid-collision">Avoid collision</h3>
<p>A collision happens when two or more keys produce the same hash code. In other words, multiple keys map to the same array index.</p>
<h2 id="heading-how-to-handle-collisions">How to Handle Collisions</h2>
<p>Hash maps use collision resolution techniques to deal with collisions. Common strategies include:</p>
<h4 id="heading-chaining">Chaining</h4>
<p>To manage several values with the same hash code, chaining involves storing a linked list or other data structure at each array index.  If a collision occurs, the new key-value pair is appended to the linked list at the relevant index.</p>
<h4 id="heading-open-addressing">Open addressing</h4>
<p>When a collision happens in a hash table, a technique called open addressing is employed to resolve it by searching for the next open space. </p>
<p>All it does is search the array for the next empty slot where the key-value combination can be placed. Methods including double hashing, quadratic probing, and linear probing are applied.</p>
<p><strong>Linear Probing:</strong> In linear probing, the algorithm moves linearly to the next index in the array in order to find the next open slot when a collision occurs.</p>
<p><strong>Quadratic Probing:</strong> In this method, an algorithm employs a quadratic function to find the next slot that becomes available.</p>
<p><strong>Double Hashing:</strong> In double hashing, the algorithm calculates the step size between probes using a secondary hash function.</p>
<p>In order to reduce the possibility of collisions, a good hash function should generate distinct hash codes for various inputs. By making sure the hash codes are evenly distributed throughout the range of potential values, collisions can be prevented.</p>
<h2 id="heading-how-to-solve-the-two-sum-problem">How to Solve the Two Sum Problem</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/image-117.png" alt="Image" width="600" height="400" loading="lazy">
<em>Two sum problem</em></p>
<p>The Two Sum problem involves finding all pairs of elements in an array that sum up to a specific target value. Now let's look at the problem statement.</p>
<h3 id="heading-problem-statement">Problem statement</h3>
<p>Given an array of integers <code>nums</code> and an integer <code>target</code>, return the indices of the two numbers such that they add up to the <code>target</code>.</p>
<p><em>Example 1:</em></p>
<p><strong>Input:</strong> nums = [3,2,4, 8], target = 12</p>
<p><strong>Output:</strong> [2, 3]</p>
<p><em>Example 2:</em></p>
<p><strong>Input:</strong> nums = [5,5], target = 10 </p>
<p><strong>Output:</strong> [0,1]</p>
<h3 id="heading-solution">Solution</h3>
<p>To solve the Two Sum problem, we can use a hash table. The idea is to traverse the <code>nums</code> array and, for each element, check if the complement (the difference between the target and the current element) is already in the hash table. If it is, we have found a pair of indices whose elements add up to the target.</p>
<p>Here are the steps to follow:</p>
<ol>
<li>To hold the elements and their respective indices, create an empty hash table upon initialization.</li>
<li>Go over the array of <code>nums</code>.</li>
<li>Do the complement calculation (target - current element) for each element.</li>
<li>Verify if the complement has already been added to the hash table.  If yes, return the current index and the index stored in the hash table for the complement.</li>
<li>If the complement is not in the hash table, store the current element and its index in the hash table.</li>
<li>If no such pair is found during the traversal, it implies that there is no solution.</li>
</ol>
<h5 id="heading-php-code-solution">PHP Code Solution</h5>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">twoSum</span>(<span class="hljs-params">$nums, $target</span>) </span>{
    $hashTable = [];

    <span class="hljs-keyword">foreach</span> ($nums <span class="hljs-keyword">as</span> $i =&gt; $num) {
        $complement = $target - $num;

        <span class="hljs-keyword">if</span> (array_key_exists($complement, $hashTable)) {

            <span class="hljs-comment">// Found the pair, return the indices</span>
            <span class="hljs-keyword">return</span> [$hashTable[$complement], $i];
        }

        <span class="hljs-comment">// Store the current element in the hash table</span>
        $hashTable[$num] = $i;
    }

    <span class="hljs-comment">// No solution found</span>
    <span class="hljs-keyword">return</span> [];
}

<span class="hljs-comment">// Example usage:</span>
$nums = [<span class="hljs-number">2</span>, <span class="hljs-number">7</span>, <span class="hljs-number">11</span>, <span class="hljs-number">5</span>, <span class="hljs-number">15</span>, <span class="hljs-number">30</span>];
$target = <span class="hljs-number">12</span>;
$result = twoSum($nums, $target);

<span class="hljs-keyword">echo</span> <span class="hljs-string">"Indices of the two numbers: ["</span> . implode(<span class="hljs-string">", "</span>, $result) . <span class="hljs-string">"]"</span>;
</code></pre>
<h5 id="heading-javascript-code-solution-using-map-function">JavaScript Code Solution using <code>map</code> Function</h5>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">twoSum</span>(<span class="hljs-params">nums, target</span>) </span>{
    <span class="hljs-keyword">const</span> hashTable = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>();

    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">const</span> [index, num] <span class="hljs-keyword">of</span> nums.entries()) {
        <span class="hljs-keyword">const</span> complement = target - num;

        <span class="hljs-comment">// Check if the complement is in the Map</span>
        <span class="hljs-keyword">if</span> (hashTable.has(complement)) {

            <span class="hljs-comment">// Found the pair, return the indices</span>
            <span class="hljs-keyword">return</span> [hashTable.get(complement), index];
        }

        <span class="hljs-comment">// Store the current number and its index in the Map</span>
        hashTable.set(num, index);
    }

    <span class="hljs-comment">// No solution found</span>
    <span class="hljs-keyword">return</span> [];
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> nums = [<span class="hljs-number">2</span>, <span class="hljs-number">7</span>, <span class="hljs-number">11</span>, <span class="hljs-number">5</span>, <span class="hljs-number">15</span>, <span class="hljs-number">30</span>];
<span class="hljs-keyword">const</span> target = <span class="hljs-number">12</span>;
<span class="hljs-keyword">const</span> result = twoSum(nums, target);

<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Indices of the two numbers that add up to <span class="hljs-subst">${target}</span>: [<span class="hljs-subst">${result.join(<span class="hljs-string">', '</span>)}</span>]`</span>);
</code></pre>
<p>This approach has a time complexity of O(n) because we iterate through the array once. The space complexity is also O(n) due to the storage of elements in the hash map.</p>
<h2 id="heading-resources">Resources</h2>
<ol>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Hash_table">Hash table From Wikipedia</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=RcZsTI5h0kg">Hash maps in Python</a></li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, you learned about hash maps, things to consider when writing hash functions and a real world problem that involves solving the Two Sum problem.</p>
<p>Keep learning, and Happy Coding!</p>
<p>You can find me on <a target="_blank" href="https://www.linkedin.com/in/suleolanrewaju/">LinkedIn</a> and <a target="_blank" href="https://twitter.com/bigdevlarry">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Minimum Stability In Composer? ]]>
                </title>
                <description>
                    <![CDATA[ Composer is a dependency management tool for projects running on PHP. PHP frameworks like Laravel, Symfony, and CodeIgniter use Composer to manage libraries and packages. In this tutorial, you’ll learn the following: Introduction to Composer. Minimu... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-minimum-stability-in-composer/</link>
                <guid isPermaLink="false">66ba2fe86e35b2ef1a340075</guid>
                
                    <category>
                        <![CDATA[ dependency management ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Wed, 09 Aug 2023 17:31:49 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/08/javier-garcia-chavez-bdZ3bzRde5g-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Composer is a dependency management tool for projects running on PHP. PHP frameworks like Laravel, Symfony, and CodeIgniter use Composer to manage libraries and packages.</p>
<p>In this tutorial, you’ll learn the following:</p>
<ul>
<li>Introduction to Composer.</li>
<li>Minimum stability in Composer.</li>
<li>Levels of stability, and the recommended version for production code.</li>
</ul>
<p>One of the benefits of using a dependency tool is that it makes it easy to declare the key-value pair of packages you need for your project. This way, you can install dependencies via the <code>composer install</code> command or update them via the <code>composer update</code> command in the terminal.</p>
<h2 id="heading-introduction-to-composer">Introduction to Composer</h2>
<p>In Laravel, the <code>composer.json</code> is a JSON file located at the root of the project directory. It contains sample configurations used for dependency management, such as the project name, type (optional), description (optional), and the list of required packages.</p>
<p>These packages are represented using key-value pairs (name and version to be installed). Additionally, the <code>composer.json</code> file includes some required packages for the development environment which can be added as part of the configuration setup.</p>
<p>Here's what a <code>composer.json</code> file looks like:</p>
<pre><code>{
    <span class="hljs-string">"name"</span>: <span class="hljs-string">"laravel/laravel"</span>,    
    <span class="hljs-string">"type"</span>: <span class="hljs-string">"project"</span>,    
    <span class="hljs-string">"description"</span>: <span class="hljs-string">"The Laravel Framework."</span>,    
    <span class="hljs-string">"keywords"</span>: [        
        <span class="hljs-string">"framework"</span>,        
        <span class="hljs-string">"laravel"</span>    
    ],    
    <span class="hljs-string">"license"</span>: <span class="hljs-string">"MIT"</span>,    
    <span class="hljs-string">"require"</span>: {        
       <span class="hljs-string">"php"</span>: <span class="hljs-string">"^8.1"</span>,        
       <span class="hljs-string">"laravel/framework"</span>: <span class="hljs-string">"^10.0"</span>,    
    },    
    <span class="hljs-string">"require-dev"</span>: {    
         .    
         .     
    },    
    <span class="hljs-string">"config"</span>: {    
         .    
         .    
    },    
    <span class="hljs-string">"minimum-stability"</span>: <span class="hljs-string">"dev"</span>| <span class="hljs-string">"alpha"</span>| <span class="hljs-string">"beta"</span>| <span class="hljs-string">"RC"</span>|<span class="hljs-string">"stable"</span>, <span class="hljs-comment">//stable</span>
}
</code></pre><h2 id="heading-what-is-minimum-stability">What is Minimum Stability?</h2>
<p>In Composer, the “minimum-stability” configuration specifies the minimum stability level for all installed packages.</p>
<p>Packages to be installed or updated will use the <code>minimum-stability</code> value to determine version limitations during dependency resolution.</p>
<h3 id="heading-levels-of-stability">Levels of Stability</h3>
<p>The following are the different stability levels:</p>
<ul>
<li><code>dev</code>: This is the least stable version, and should never be used in production. It often includes packages under active development that may contain bugs or breaking changes and may still undergo significant modifications. It is only recommended for local development purposes.</li>
<li><code>alpha</code>: It's a version also undergoing development but in a more stable state. It usually contains fewer breaking changes and features nearing final completion or awaiting a beta release. However, it is also not highly recommended for production environments.</li>
<li><code>beta</code>: This version is currently being tested, and minor bugs, when noticed, will need to be fixed. However, it is more stable than the alpha and dev versions, but it's still not recommended for production purposes.</li>
<li><code>RC</code>: The RC (Release Candidate) is a version pending official release. It's the closest to being stable, but the version requires community testing and feedback prior to the final release. Undiscovered bugs can also be identified during this phase, so it's best practice not to use it for production purposes.</li>
<li><code>stable</code>: This is the required level for production purposes. It includes all packages that have gone through significant changes, bug fixes, community testing, feedback, and is now ready to use.</li>
</ul>
<p>In your <code>composer.json</code>, you can specify the minimum stability by doing the following:</p>
<pre><code>{
    <span class="hljs-string">"minimum-stability"</span>: <span class="hljs-string">"stable"</span>
}
</code></pre><h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, you have learned about Composer, the <code>composer.json</code> file, minimum stability, and, most importantly, the levels of stability offered by Composer. </p>
<p>For your application, you should carefully choose the stability level that satisfies your production needs, while keeping security and downtime issues in mind. Remember, your application should only depend on stable and reliable packages.</p>
<p>I hope you now have a better understanding of minimum stability.</p>
<p>Keep learning, and Happy Coding!</p>
<p>You can find me on <a target="_blank" href="https://www.linkedin.com/in/suleolanrewaju/">LinkedIn</a> and <a target="_blank" href="https://twitter.com/bigdevlarry">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Logging Works in Laravel Applications ]]>
                </title>
                <description>
                    <![CDATA[ Logs are records of the events happening with your application. Laravel, by default, writes log information into the laravel.log file that ships with a fresh Laravel installation. The file is housed within the storage > logs directory.  In this tutor... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/laravel-logging/</link>
                <guid isPermaLink="false">66ba2fc97787ec7052709314</guid>
                
                    <category>
                        <![CDATA[ lavarel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ logging ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Fri, 06 Jan 2023 19:38:55 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/how-logging-works-laravel.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Logs are records of the events happening with your application. Laravel, by default, writes log information into the laravel.log file that ships with a fresh Laravel installation. The file is housed within the <code>storage &gt; logs</code> directory. </p>
<p>In this tutorial, you'll learn the following:</p>
<ul>
<li>Introduction to logging</li>
<li>Understanding log configurations</li>
<li>Channel drivers for log files</li>
<li>Formatting log messages</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screenshot-2023-01-05-at-23.26.03.png" alt="Image" width="600" height="400" loading="lazy">
<em>Log file image</em></p>
<h2 id="heading-introduction-to-logging">Introduction to Logging</h2>
<p>Laravel provides a log of what's happening in your application. The log service is built upon the Monolog open-source library. </p>
<p>The logging service is robust as it allows you to write log messages to files and send critical ones to teams on Slack (if configured), Socket, databases, and other web services. </p>
<p>The channel you wish to write your log information on is defined by the team, as there are a couple of channels supported by Laravel. Based on the severity of log information, the write information can also be done in multiple channels. You'll see how you can do this in the configuration section.</p>
<h2 id="heading-how-to-configure-your-laravel-logs">How to Configure Your Laravel Logs</h2>
<p>Laravel log configuration is located in the <strong>config &gt; logging.php</strong> file. Consider using a couple of log channels based on your preferences, such as stack, single, daily, syslogs, slack, papertail, and so on. </p>
<p>The channels are where you send log information. The default channel for every project is usually <strong>stack</strong>. You can change it by defining the <code>LOG_CHANNEL</code> in the env or specifying the channel name as the second parameter in the same <strong>logging.php</strong> file.</p>
<pre><code><span class="hljs-string">'default'</span> =&gt; env(<span class="hljs-string">'LOG_CHANNEL'</span>, <span class="hljs-string">'stack'</span>)
</code></pre><p>The stack channel has a driver name set to <code>stack</code>. Channels set to <code>single</code> means you get all logs in a single log file. You can also use <code>daily</code> which means a new log is auto-generated every day. It is an array. </p>
<p>You can also use multiple channels, <code>'channels' =&gt; ['daily', 'slack']</code>, and <code>ignore_exception</code> is a boolean (true, false). </p>
<p>I highly recommend using the daily channel, as this helps you keep track of daily logs by auto-generating a new log file every day (laravel-2023-01-15.log, laravel-2023-01-16.log and so on) without having to clear logs for the previous day. </p>
<p>The daily options keep you updated each day with log info in your log files for as long as you want. It also enables you to monitor frequent errors within the application if they occur on different days.</p>
<pre><code class="lang-php"> <span class="hljs-string">'channels'</span> =&gt; [        
    <span class="hljs-string">'stack'</span> =&gt; [ 
        <span class="hljs-string">'driver'</span> =&gt; <span class="hljs-string">'stack'</span>,            
        <span class="hljs-string">'channels'</span> =&gt; [<span class="hljs-string">'daily'</span>],    
        <span class="hljs-string">'ignore_exceptions'</span> =&gt; <span class="hljs-literal">false</span>,        
        ],
....],
</code></pre>
<h2 id="heading-channel-drivers-for-log-files">Channel Drivers for Log Files</h2>
<p>Here’s the list of the channel drivers Laravel offers:</p>
<ol>
<li><code>Single</code>: The Single driver ensures log information is sent to a single file. The driver sends logs to <strong>storage &gt; logs &gt; laravel.log</strong> by default.</li>
<li><code>daily</code>: The driver ensures that logs are written daily. The beauty about this is that every day new log file is auto-generated. Compared to the Single driver, there's no need to clear up the previous day's log information frequently. But the drawback to this channel is that you might have several log files. Every week/month, you should clear up all unused files.</li>
</ol>
<p>Within the logs directory, you often get logs like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Screenshot-2022-12-26-at-13.29.50.png" alt="Image" width="600" height="400" loading="lazy">
<em>Daily log file</em></p>
<ol start="3">
<li><code>slack</code>: The slack driver ensures that all logs are sent to Slack. Slack needs to be configured to get user credentials (username, webhook) to help with error logging. This is super helpful as it allows your team to stay updated about what's happening right in a Slack channel. </li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Screenshot-2022-12-26-at-13.19.26.png" alt="Image" width="600" height="400" loading="lazy"></p>
<ol start="4">
<li><p><code>syslog</code>: Logs using this driver will send log reports to the system log. The location of this log driver is dependent on the server operating system.</p>
</li>
<li><p><code>errorlog</code>: Logs set up to use this driver will send log reports to the error logs file setup on the web server operating system.</p>
</li>
<li><p><code>monolog</code>: This driver provides support for all Monolog handlers.</p>
</li>
<li><p><code>custom</code>: This driver helps create a custom channel based on user preference. It could be to a third-party service that needs log reports.</p>
</li>
<li><p><code>stack</code>: The stack driver is responsible for creating multiple channels</p>
</li>
<li><p><code>null</code>: All log messages get discarded by the driver.</p>
</li>
</ol>
<h2 id="heading-how-to-format-log-messages">How to Format Log Messages</h2>
<p>If you need a refresher on how facades work or how to create one, you should refer to this article about <a target="_blank" href="https://www.freecodecamp.org/news/how-to-use-facades-in-laravel/">how facades work in Laravel</a>.  </p>
<p>Laravel has a <code>Log</code> facade that helps with writing logs. Import the facade at the top of the file to use any log level.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</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">Log</span>; 


Log::info($message);
</code></pre>
<p>You can also choose to escape the <code>Log</code> facade, so you won't need to import anything. This is suitable if you're logging a single instance of log info.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

\Log::info($message);
</code></pre>
<p>In a recent Laravel release, logging has greatly improved. You can do away with the Log facade while logging info and reference the <code>info</code> from within your Laravel application.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

info($message);
</code></pre>
<p>Other logging levels used to write information include <strong>alert, emergency, critical, warning, error, notice, and debug</strong>.</p>
<p>Within a file, you can log any of the data types or messages and even format the output of text you wish to write to the log file. </p>
<h3 id="heading-how-to-format-strings-booleans-and-integers">How to format strings, booleans, and integers:</h3>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</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">Log</span>;


Log::warning(<span class="hljs-string">'There is a warning'</span>); 

Log::error(<span class="hljs-literal">false</span>);

Log::notice(<span class="hljs-number">500</span>);
</code></pre>
<h3 id="heading-how-to-format-to-an-array">How to format to an array:</h3>
<p>You can also format to an array. With the array function, a new array is created. So we can write an array to the log file by passing the log info to the array function. The <code>json_decode</code> converts the JSON object to a PHP object, and the <code>true</code> ensure it returns associative arrays (key and value pairs).</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

$person = <span class="hljs-string">'{"Peter":35, "John":37, "Yinka":43}'</span>; 

$data = json_decode($person, <span class="hljs-literal">true</span>);

info($data);
</code></pre>
<h3 id="heading-how-to-format-to-an-object">How to format to an object:</h3>
<p>You can also write JSON objects to the log file when working with logs. Use the <code>json_encode</code> to encode values into JSON format.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span> 

$data = [<span class="hljs-string">"Peter"</span>=&gt; <span class="hljs-number">35</span>, <span class="hljs-string">"John"</span>=&gt; <span class="hljs-number">37</span>, <span class="hljs-string">"Yinka"</span> =&gt; <span class="hljs-number">43</span>];

info(json_encode($data));
</code></pre>
<h3 id="heading-how-to-concatenate-string-with-array-or-objects">How to concatenate string with array or objects:</h3>
<p>This is helpful when including a string to track the log information. You can do this using the concatenation operator (.)</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

$persons = [<span class="hljs-string">"Peter"</span>=&gt; <span class="hljs-number">35</span>, <span class="hljs-string">"John"</span>=&gt; <span class="hljs-number">37</span>, <span class="hljs-string">"Yinka"</span> =&gt; <span class="hljs-number">43</span>];

info(<span class="hljs-string">'The person info '</span> . json_encode($persons));
</code></pre>
<h3 id="heading-how-to-write-to-dedicated-channels">How to write to dedicated channels:</h3>
<p>This method is helpful when you feel there's a need to write into specific channels aside from the default log channel. It would help if you had to specify the channel name when calling the Log facade.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>


\Log::channel(<span class="hljs-string">'slack'</span>)-&gt;info(<span class="hljs-string">'registeration successful'</span>);
</code></pre>
<p>The snippet above ensures the write operation is done on the Slack channel. Also, the stack method allows logging on multiple channels.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>


\Log::stack([<span class="hljs-string">'single'</span>, <span class="hljs-string">'slack'</span>])-&gt;info(<span class="hljs-string">'registeration successful!'</span>);
</code></pre>
<p>You can learn more about custom channels via factories and monolog channel customization from the <a target="_blank" href="https://laravel.com/docs/master/logging">official documentation</a>.</p>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>In this article, you have learnt about logging, configuring logs in your Laravel application, available channel drivers, and how to write log files in different formats. </p>
<p>You should now have a better understanding of laravel logging. Keep learning, and Happy Coding!</p>
<p>You can find me on <a target="_blank" href="https://www.linkedin.com/in/suleolanrewaju/">LinkedIn</a> and <a target="_blank" href="https://twitter.com/bigdevlarry">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Laravel Valet Performance – How to Prevent 504 Errors and Speed Up Valet ]]>
                </title>
                <description>
                    <![CDATA[ Last week, I decided to install Laravel Valet on my Mac. But after the installation, the performance of the microservice architecture application I had it on was quite slow.  I wondered if it was an M1 issue or because I had yet to shut the machine d... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/speed-up-performance-in-laravel-valet/</link>
                <guid isPermaLink="false">66ba2fcfde9370f66eeb0a9d</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Mon, 02 Jan 2023 23:12:30 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/pexels-jonathan-petersson-399636.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Last week, I decided to install Laravel Valet on my Mac. But after the installation, the performance of the microservice architecture application I had it on was quite slow. </p>
<p>I wondered if it was an M1 issue or because I had yet to shut the machine down. I shut down, and the problem persisted. And I couldn't find anything online indicating that it was an issue with M1. So how could I fix it?</p>
<p><strong>In this tutorial, you'll learn:</strong></p>
<ul>
<li>Why does the Error 504 occur?</li>
<li>What is Laravel Valet and how does it work?</li>
<li>Valet commands you should know</li>
<li>How to fix the 504 error and speed up performance in Valet</li>
</ul>
<h2 id="heading-why-does-the-error-504-occur">Why does the Error 504 occur?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-145.png" alt="Image" width="600" height="400" loading="lazy">
<em>Error 504 Nginx</em></p>
<p>Error 504, also known as "Gateway timeout", is an error that occurs when a server takes longer than usual to respond to an HTTP request. This makes it unable to complete the request cycle. </p>
<p>The Gateway timeout is a server-side error caused by several things. It can result from network connectivity issues when the server exceeds the default limit of <strong>256M</strong> or an execution time of <strong>60 seconds</strong>, an overloaded server, firewall, and so on. </p>
<p>This error happens with local servers, too, such as XAMPP, WAMP and Valet, during the local development lifecycle. </p>
<p>This article will help you fix this problem on Valet by adding some configurations to speed up the server request lifecycle.</p>
<h2 id="heading-what-is-laravel-valet-and-how-does-it-work">What is Laravel Valet and How Does It Work?</h2>
<p>Laravel Valet is a development environment for macOS, Windows, and other operating systems. Once installed, Valet runs Nginx processes in the background when your laptop comes on.</p>
<p>Unlike other development environments like XAMPP and WAMP, you'll have to manually start your server each time you set out to work. Valet then uses DnsMasq to proxy all parked applications to a <code>.test</code> domain. </p>
<p>So, for instance, you would access on XAMPP server <code>http://localhost/application</code> but on valet, you would do <code>http://application.test</code>, and it will point to where the application is installed. </p>
<p>Working with Valet means you don't have to put all applications in an htdocs or www directory. Instead, any random directory you create will work just perfectly in Valet. </p>
<h2 id="heading-helpful-valet-commands-you-should-know">Helpful Valet Commands You Should Know:</h2>
<ul>
<li><strong><code>valet park</code>:</strong> Registers all applications/sites in a directory and exposes them with the .test domain.</li>
</ul>
<pre><code>cd ~/project_directory
valet park
</code></pre><ul>
<li><strong><code>valet parked</code>:</strong> Gives a tabular breakdown of all registered sites. Information like site name, SSL, URL, and path is available.</li>
</ul>
<pre><code>cd ~/project_directory
valet parked
</code></pre><ul>
<li><strong><code>valet secure</code>:</strong> Secures your application with an SSL certificate and makes the site accessible over HTTPS.</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet secure
</code></pre><ul>
<li><strong><code>valet unsecure</code>:</strong> Use this command to unsecure your site and revert to serving over HTTP.</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet unsecure
</code></pre><ul>
<li><strong><code>valet isolate</code>:</strong> Isolates a particular site and makes it run on a different PHP version that's not the globally installed version. You can run <code>php -v</code> on the terminal to see the version. But if some of your applications want to downgrade or upgrade, you should use the isolate command and specify the version you need. The isolate command below, enforce the site to use PHP version 7.4:</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet isolate @php7<span class="hljs-number">.4</span>
</code></pre><ul>
<li><strong><code>valet unisolate</code>:</strong> Reverts a site back to the globally installed PHP version.</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet unisolate
</code></pre><ul>
<li><strong><code>valet restart</code>:</strong> The restart command ensures all valet services are restarted. It's useful when configurations are modified, updated, and installed.</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet restart
</code></pre><ul>
<li><strong><code>valet -v</code>:</strong> This command helps check the the current Valet version. Not only that, but the command also shows a list of all available commands and descriptions of what they do in Valet.</li>
</ul>
<pre><code>~<span class="hljs-regexp">/project_directory/</span>site
valet -v
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Screenshot-2022-12-26-at-11.33.10.png" alt="Image" width="600" height="400" loading="lazy">
<em>Valet available commands</em></p>
<h2 id="heading-how-to-speed-up-performance-in-valet">How to Speed Up Performance in Valet</h2>
<p>Over in the terminal, we will need to create a file <code>www.conf</code> in a directory and then add the configuration settings we need.</p>
<p>Get your PHP global version and copy it like this:</p>
<pre><code>php -v
</code></pre><p>Navigate to the directory and replace the 7.4 with the PHP version you copied earlier.</p>
<pre><code>cd /opt/homebrew/etc/php/<span class="hljs-number">7.4</span>/php-fpm.d
</code></pre><p>Create a <code>www.conf</code> file like this:</p>
<pre><code>touch www.conf
</code></pre><p>Open the file so you can add the valet configuration settings:</p>
<pre><code>open -a TextEdit www.conf
</code></pre><p>The command opens up the <code>www.conf</code> file in your text editor and you can update the file with these settings:</p>
<pre><code>pm.max_children = <span class="hljs-number">200</span>
pm.start_servers = <span class="hljs-number">20</span>
pm.min_spare_servers = <span class="hljs-number">10</span>
pm.max_spare_servers = <span class="hljs-number">20</span>
pm.process_idle_timeout = <span class="hljs-number">10</span>s
pm.max_requests = <span class="hljs-number">500</span>
</code></pre><p>Save and close the file from the text editor.</p>
<p>Let's go through each line we added to the <code>www.conf</code> file:</p>
<ul>
<li><strong><code>pm</code></strong> is an acronym for process manager, and the setting will impact how the process manager controls every child process. The possible values available to us include static, on-demand, and dynamic.</li>
<li><strong>pm.max_children</strong> is a static option, indicating the maximum number of the child processes, which we have set to 200.</li>
<li><strong><code>pm.start_servers, pm.max_spare_servers</code></strong> and <code>pm.min_spare_servers</code>: These are dynamic values, and the child processes are set dynamically based on the server directives – that is, start_servers = 20, min_spare_servers = 10 and max_spare_servers = 20.</li>
<li><strong>pm.process_idle_timeout</strong>: the total time taken for an idle request not processed to be killed/terminated is set to a default value of 10 seconds (s). Other units can be estimated in minutes (m), hours (h) or days (d).</li>
<li><strong>pm.max_requests</strong>: This refers to the maximum number of requests a child process can handle at a given time before it's killed/terminated. If the request executes the maximum, it becomes idle, and the pm gets rid of it.</li>
</ul>
<p>Finally, restart all services from the terminal using the sudo brew command. Notice again the 7.4 – that's because of my global PHP version.</p>
<pre><code>sudo brew services restart php@<span class="hljs-number">7.4</span>
</code></pre><p>You can now say bye-bye to the 504 error and slow Valet performance in your local environment.</p>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>In this article, you have learned about working with Laravel Valet and how to get all Valet configurations set up. You also learned how to ensure a fast development environment and get rid of persistent 504 gateway timeout errors. </p>
<p>Keep learning and Happy Coding!</p>
<p>You can find me on <a target="_blank" href="https://www.linkedin.com/in/suleolanrewaju/">LinkedIn</a> and <a target="_blank" href="https://twitter.com/bigdevlarry">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use the SQL CASE Statement – with Example Challenge ]]>
                </title>
                <description>
                    <![CDATA[ Writing SQL with multiple conditions can be an arduous task, especially if you need to make numerous checks.  For example, an if () else if () else {} check case expression handles all SQL conditionals. If the first condition is satisfied, the query ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/sql-case-statement/</link>
                <guid isPermaLink="false">66ba2fd254ccc2d852dc891c</guid>
                
                    <category>
                        <![CDATA[ database ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SQL ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Fri, 04 Nov 2022 14:28:57 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/Sql-case-banner.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Writing SQL with multiple conditions can be an arduous task, especially if you need to make numerous checks. </p>
<p>For example, an <code>if () else if () else {}</code> check case expression handles all SQL conditionals. If the first condition is satisfied, the query stops executing with a return value. The value specified within the else is returned if no condition is satisfied.</p>
<p>In this article, we'll cover:</p>
<ol>
<li>What the SQL CASE statement is and how it works</li>
<li>How to solve an exercise using the SQL CASE statement</li>
<li>What some important terms mean, like order by, limit, offset, left join and alias.</li>
</ol>
<h2 id="heading-sql-case-statement-explained">SQL CASE Statement Explained</h2>
<p>In programming when you have a given set of conditions, you end up using conditionals (<code>switch</code> or <code>if else</code>) to know which block of code to execute when a condition is met. </p>
<p>With SQL, you can do this using the CASE statement. You use the CASE keyword together with the WHEN clause to execute a block of conditional statement code. You use a THEN statement to return the result of the expression. If none of the conditions are met, then you use a final ELSE clause to return a fallback result. </p>
<p>The <strong>SQL CASE statement has the following syntax</strong>:</p>
<pre><code class="lang-sql">CASE
    WHEN conditional_statement1 THEN result1
    .
    .
    .
    .
    WHEN condition_statementN THEN resultN

    ELSE result
<span class="hljs-keyword">END</span>;
</code></pre>
<p>When you use the CASE statement, it has to be followed by a WHEN and THEN the result if the first condition is met. If the first condition is not met it keeps on checking the other conditions until the nth (or final) condition. If that is still not met then the ELSE condition gets executed. </p>
<p>Also, the ELSE part is optional when using the CASE statement. In scenarios where you don't use it, the query result returns NULL.</p>
<h2 id="heading-sql-challenge">SQL Challenge</h2>
<p>In this section, we will take a case study of a real-life scenario to help you learn how to solve a SQL challenge that uses the CASE statement. </p>
<p>The challenge is one I encountered on Coderbyte, a platform for practicing coding challenges. It was a bit tough to crack, and I will break down the step-by-step process involved in this article.</p>
<h3 id="heading-what-is-the-challenge">What is the challenge?</h3>
<p>The challenge involves coming up with a SQL query to return the employee with the third-highest salary from a table. </p>
<p>You'll need to structure a query to find this employee and return that row. You also have to replace the position of the DivisionID column with the corresponding DivisionName from the table company_divisions. Then you'll need to replace the ManagerID column with the ManagerName if the ID exists in the table and is not NULL.</p>
<h3 id="heading-what-problem-does-the-sql-case-statement-solve-in-this-challenge">What problem does the SQL CASE statement solve in this challenge?</h3>
<p>In this challenge, we need the CASE statement to help achieve the followings:</p>
<ol>
<li>Ensure that the MangerID is not NULL.</li>
<li>Match the company ManagerID to company ID and return the Name as the ManagerName.</li>
<li>Ensure that if no Name is returned, then the name Susan Wall is used as the default ManagerName.</li>
</ol>
<p><strong>Here's the expected output:</strong></p>
<table>
    <tbody><tr>
        <th>ID</th>
        <th>Name</th>
        <th>DivisionName</th>
        <th>ManagerName</th>
        <th>Salary</th>
    </tr>
    <tr>
          <td>222</td>
          <td>Mark Red</td>
          <td>Sales</td>
        <td>Susan Wall</td>
          <td>86000</td>
     </tr>
</tbody></table>


<p>And here's the data you'll need to solve this challenge:</p>
<h4 id="heading-table-1-company">Table 1: company</h4>
<table>
    <tbody><tr>
        <th>ID</th>
        <th>Name</th>
        <th>DivisionID</th>
        <th>ManagerID</th>
        <th>Salary</th>
    </tr>
    <tr>
        <td>356</td>
        <td>Daniel smith</td>
        <td>100</td>
        <td>133</td>
        <td>40000</td>
    </tr>
    <tr>
        <td>122</td>
        <td>Arnold Sully</td>
        <td>101</td>
        <td>null</td>
        <td>60000</td>
    </tr>
    <tr>
        <td>467</td>
        <td>Lisa Roberts</td>
        <td>100</td>
        <td>null</td>
        <td>80000</td>
    </tr>
    <tr>
        <td>112</td>
        <td>Mary Dial</td>
        <td>105</td>
        <td>467</td>
        <td>65000</td>
    </tr>
    <tr>
        <td>775</td>
        <td>Dennis Front</td>
        <td>103</td>
        <td>null</td>
        <td>90000</td>
    </tr>
    <tr>
        <td>111</td>
        <td>Larry Weis</td>
        <td>104</td>
        <td>35534</td>
        <td>75000</td>
    </tr>
    <tr>
        <td>222</td>
        <td>Mark Red</td>
        <td>102</td>
        <td>133</td>
        <td>86000</td>
    </tr>
    <tr>
        <td>577</td>
        <td>Robert Niger</td>
        <td>105</td>
        <td>12353</td>
        <td>76000</td>
    </tr>
    <tr>
        <td>133</td>
        <td>Susan Wall</td>
        <td>105</td>
        <td>577</td>
        <td>110000</td>
    </tr>
</tbody></table>



<h4 id="heading-table-2-companydivisions">Table 2: company_divisions</h4>
<table>
    <tbody><tr>
        <th> ID </th>
        <th> </th>
        <th> DivisionName </th>
    </tr>
    <tr>
        <td> 100 </td>
        <td> </td>
        <td> Accounting </td>
    </tr>
    <tr>
        <td> 101 </td>
        <td> </td>
        <td> IT </td>
    </tr>
    <tr>
        <td> 102 </td>
        <td> </td>
        <td> Sales </td>
    </tr>
    <tr>
        <td> 103 </td>
        <td> </td>
        <td> Marketing </td>
    </tr>
    <tr>
        <td> 104 </td>
        <td> </td>
        <td> Engineering </td>
    </tr>
    <tr>
        <td> 105 </td>
        <td> </td>
        <td> Customer Support </td>
    </tr>
</tbody></table>

<h2 id="heading-how-to-solve-the-sql-case-statement-challenge">How to Solve the SQL CASE Statement Challenge</h2>
<p>In this section, we will look at the step-by-step process involved in solving the challenge.</p>
<h3 id="heading-step-1-get-the-third-highest-salary">Step 1: Get the third-highest salary</h3>
<p>First, you'll need to structure a query to return the third-highest salary. You'll do this by selecting from the company table and ordering by salary (since we're interested in the record with the third-highest salary). </p>
<p>You can do that like this:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> *

<span class="hljs-keyword">FROM</span> company

<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> salary <span class="hljs-keyword">DESC</span> <span class="hljs-keyword">limit</span> <span class="hljs-number">1</span> <span class="hljs-keyword">offset</span> <span class="hljs-number">2</span>;
</code></pre>
<p>The query returns the employee's row with the third highest salary, as expected.</p>
<br><table>
    <tbody><tr>
         <th>ID</th>
        <th>Name</th>
        <th>DivisionID</th>
        <th>ManagerID</th>
        <th>Salary</th>    </tr>
    <tr>
        <td>222</td>
        <td>Mark Red</td>
        <td>102</td>
        <td>133</td>
        <td>86000</td>
    </tr>
</tbody></table>

<p>So what's going on in this query?</p>
<p><code>SELECT</code>: you use the SELECT command with the asterisk (<em>), also known as a wildcard) to retrieve all columns from the <em>*company</em></em> table.</p>
<p><code>ORDER BY</code>: The ORDER BY command orders column(s) in ascending or descending order. SQL orders by ascending (<strong>ASC</strong>) by default, but we will order the salary column by descending (<strong>DESC</strong>). This is because we need the desc salary from the highest to the lowest, that is 110,000 - 40,000.</p>
<p><code>limit</code>: The limit command limits the number of records returned based on the limit's set value. Since we are only interested in just one row, we will set the limit in the query to 1. This ensures that we will get a return value of a single record every time this query gets executed.</p>
<p><code>offset</code>: Using the offset clause here helps you specify the number of rows to skip before the start of actually returning the row from the query. Offset lets us skip the two highest-paid rows (Susan Wall and Dennis Front) and return the third highest-paid (Mark Red).</p>
<h3 id="heading-step-2-replace-divisionid-with-divisionname">Step 2: Replace DivisionID with DivisionName</h3>
<p>Now, you need to modify the query by selecting only the columns you need – ID, Name, ManagerID, DivisionName, and Salary. Then you need to replace the DivisionID column with the corresponding DivisionName from the table <strong>company_divisions</strong>.</p>
<p>You can do that like this:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> c.ID, c.Name, c.ManagerID, c.salary, cd.DivisionName

<span class="hljs-keyword">FROM</span> company <span class="hljs-keyword">as</span> c

<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> company_divisions <span class="hljs-keyword">as</span> cd <span class="hljs-keyword">ON</span> c.DivisionId = cd.id

<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> salary <span class="hljs-keyword">DESC</span> <span class="hljs-keyword">limit</span> <span class="hljs-number">1</span> <span class="hljs-keyword">offset</span> <span class="hljs-number">2</span>;
</code></pre>
<p>Here's the output:</p>
<br><table>
    <tbody><tr>
         <th>ID</th>
        <th>Name</th>
        <th>DivisionName</th>
        <th>ManagerID</th>
        <th>Salary</th>    </tr>
    <tr>
        <td>222</td>
        <td>Mark Red</td>
        <td>Sales</td>
        <td>133</td>
        <td>86000</td>
    </tr>
</tbody></table>

<p>Let's discuss what's going on in the above query:</p>
<p><code>LEFT JOIN</code>: Since records are returned from the left side (company), we will match them using the LEFT JOIN on the right side (company_divisions) using the <code>company_division.id and company.DivisionID</code>. </p>
<p>If a matching record is found, that is the company's id is also present in company division, then the DivisionName column is populated with the actual value from the left join, in our case (Sales). If there is no record, nothing is returned.</p>
<p><code>as</code> (alias): The alias used is a temporary name for the table. So rather than company.name with an alias for the company as c, we can define it as c.name. Using aliases helps improve readability.</p>
<h3 id="heading-step-3-replace-managerid-with-managername">Step 3: Replace ManagerID with ManagerName</h3>
<p>We will build on the result of the query from Step 2. We'll use the CASE statement we learned to add conditionals for when the ManagerId is not null and to check if the ManagerId also exists.</p>
<p>The first thing we need to do is check if the company.ManagerID is not null and make sure that the ID exist in the table. We will apply the CASE statement here.</p>
<pre><code class="lang-sql">CASE WHEN c.ManagerID IS NOT NULL 

AND c.ManagerID = c.ID
</code></pre>
<p>The second part of the CASE statement is to replace the ManagerID column with the ManagerName. Then we'll need to use the THEN block we learnt earlier like this:</p>
<pre><code class="lang-sql">CASE WHEN c.ManagerID IS NOT NULL 

AND c.ManagerID = c.ID

THEN Name ELSE 'Susan Wall' <span class="hljs-keyword">END</span> <span class="hljs-keyword">AS</span> <span class="hljs-string">'ManagerName'</span>
</code></pre>
<p>Finally, we can now include the CASE block into the already existing code snippet we had from STEP 2. This will look somewhat like this now:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> c.ID, c.Name, c.salary, cd.DivisionName

<span class="hljs-keyword">CASE</span> <span class="hljs-keyword">WHEN</span> c.ManagerID <span class="hljs-keyword">IS</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> 

<span class="hljs-keyword">AND</span> c.ManagerID = c.ID

<span class="hljs-keyword">THEN</span> <span class="hljs-keyword">Name</span> <span class="hljs-keyword">ELSE</span> <span class="hljs-string">'Susan Wall'</span> <span class="hljs-keyword">END</span> <span class="hljs-keyword">AS</span> <span class="hljs-string">'ManagerName'</span>

<span class="hljs-keyword">FROM</span> company <span class="hljs-keyword">as</span> c

<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> company_divisions <span class="hljs-keyword">as</span> cd <span class="hljs-keyword">ON</span> c.DivisionId = cd.id

<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> salary <span class="hljs-keyword">DESC</span> <span class="hljs-keyword">limit</span> <span class="hljs-number">1</span> <span class="hljs-keyword">offset</span> <span class="hljs-number">2</span>;
</code></pre>
<p>The result of Step 3 is the expected output – the employee with third-highest salary.</p>
<table>
    <tbody><tr>
        <th>ID</th>
        <th>Name</th>
        <th>DivisionName</th>
        <th>ManagerName</th>
        <th>Salary</th>
    </tr>
    <tr>
          <td>222</td>
          <td>Mark Red</td>
          <td>Sales</td>
        <td>Susan Wall</td>
          <td>86000</td>
     </tr>
</tbody></table>


<h2 id="heading-wrapping-up"><strong>Wrapping up</strong></h2>
<p>In this article, I hope you learned about the CASE statement in SQL and how to approach a real-world problem using CASE.</p>
<p>You also learned other SQL commands such as SELECT, ORDER BY, LIMIT, OFFSET, LEFT JOIN, and ALIAS.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Cross-Site Request Forgery (CSRF)? Laravel Web Security Tutorial ]]>
                </title>
                <description>
                    <![CDATA[ In this tutorial, you'll learn about Laravel web security and how to secure your web applications and protect them from Cross-Site Request Forgery, or CSRF attacks. CSRF is a malicious activity that involves an attacker performing actions on behalf o... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/laravel-web-security-csrf/</link>
                <guid isPermaLink="false">66ba2fccc346e93df556b001</guid>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Tue, 04 Oct 2022 21:40:49 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/Dark-Neon-Simple-Futuristic-UIUX-Designer-LinkedIn-Banner--7---1-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this tutorial, you'll learn about Laravel web security and how to secure your web applications and protect them from Cross-Site Request Forgery, or CSRF attacks.</p>
<p>CSRF is a malicious activity that involves an attacker performing actions on behalf of an authenticated user. Fortunately, Laravel provides out-of-the-box measures to prevent this type of vulnerability.</p>
<p><strong>In this tutorial, you'll learn:</strong></p>
<ul>
<li>What is CSRF?</li>
<li>How to prevent a CSRF request</li>
<li>How and where CSRF verification happens</li>
</ul>
<h2 id="heading-what-is-csrf">What is CSRF?</h2>
<p>CSRF attacks hijack user sessions. They do this by tricking a user into sending a request through hidden form tags or malicious URLs (images or links) without the user's knowledge. </p>
<p>This attack leads to a change in the state of the user session, data leaks, and attackers can sometimes manipulate end-users data in an application.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/Screenshot-2022-10-03-at-14.59.14-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>CSRF Explainer</em></p>
<p>The image above illustrates this scenario where an Actor (User) sends a request from <strong>malicious.xyz</strong> through the <strong>webserver</strong> to <strong>application.xyz</strong>. They then realize that their information has been manipulated by <strong>updating</strong> their <strong>password</strong>.</p>
<h2 id="heading-how-to-prevent-csrf-requests">How to Prevent CSRF Requests</h2>
<p>For each user session, Laravel generates secured tokens that it uses to ensure that the authenticated user is the one requesting the application. </p>
<p>Since this token changes each time a user session is regenerated, a malicious attacker can not access it. </p>
<p>Each time there’s a request to modify user information on the server-side (back end) like <code>POST</code>, <code>PUT</code>, <code>PATCH</code>, and <code>DELETE</code>, you need to include a <code>@csrf</code> in the HTML form request. The <code>@csrf</code> is thus a Blade directive used to generate a hidden token validated by the application. </p>
<p><strong>Blade directive</strong> is the syntax used within the Laravel templating engine called <strong>Blade</strong>. To create a blade file you give it a name – in our case form – followed by the blade extension. This means that the file will have the name <code>form.blade.php</code>.</p>
<p>You use the blade file to render views to users on the webpage. There are a couple of default directives or blade shorthand syntaxes you can use. For example, <code>@if</code> checks if a condition is met, <code>@empty</code> checks if records are not empty, <code>@auth</code> checks if a user is authenticated, and so on. </p>
<p>But here we are more interested with the <code>@csrf</code> directive. Here's how you use it:</p>
<pre><code class="lang-php">&lt;form method=<span class="hljs-string">"POST"</span> action=<span class="hljs-string">"{{route('pay')}}"</span>&gt;

    @csrf

&lt;/form&gt;
</code></pre>
<p>Earlier Laravel releases used to look somewhat like this – both work and do the same thing behind the scenes.</p>
<pre><code class="lang-php">&lt;form method=<span class="hljs-string">"POST"</span> action=<span class="hljs-string">"{{route('pay')}}"</span>&gt;

    &lt;input type=<span class="hljs-string">"hidden"</span> name=<span class="hljs-string">"_token"</span> value=<span class="hljs-string">"{{ csrf_token() }}"</span> /&gt;

&lt;/form&gt;
</code></pre>
<p>When the CSRF token is not present in the form request that gets sent or if it appears invalid, Laravel throws an error message "Page Expired" with a status code 419.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/Screenshot-2022-10-03-at-15.11.43-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Laravel 419 Page Expired</em></p>
<h2 id="heading-how-and-where-csrf-verification-happens">How and Where CSRF Verification Happens</h2>
<p>The <code>VerifyCsrfToken</code> middleware handles CSRF verification within the Laravel application. The middleware is registered in the Kernel.php, and found within the application's web route middleware group. This means the middleware is triggered for requests within the Web, not related to APIs.</p>
<pre><code class="lang-php"><span class="hljs-keyword">protected</span> $middlewareGroups = [
        <span class="hljs-string">'web'</span> =&gt; [
           .
           .
           .
           .
           .
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],
    ];
</code></pre>
<p>The VerifyCsrfToken middleware extends the <code>Illuminate\Foundation\Http\Middleware\VerifyCsrfToken</code> class. This means that the CSRF verification is housed within the class. </p>
<p>Let's dive deeper to learn how Laravel handles the CSRF verification. </p>
<p>Within the class, we have the <code>tokensMatch</code> function.</p>
<pre><code class="lang-php"><span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">tokensMatch</span>(<span class="hljs-params">$request</span>)
    </span>{
        $token = <span class="hljs-keyword">$this</span>-&gt;getTokenFromRequest($request);

        <span class="hljs-keyword">return</span> is_string($request-&gt;session()-&gt;token()) &amp;&amp;
               is_string($token) &amp;&amp;
               hash_equals($request-&gt;session()-&gt;token(), $token);
    }
</code></pre>
<p>The function does two things:</p>
<ol>
<li><code>$this-&gt;getTokenFromRequest</code> gets the token from the incoming request attached via a hidden field or the request's header. The token is decrypted and then returned to the token variable.</li>
</ol>
<pre><code class="lang-php"><span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getTokenFromRequest</span>(<span class="hljs-params">$request</span>)
    </span>{
        $token = $request-&gt;input(<span class="hljs-string">'_token'</span>) ?: $request-&gt;header(<span class="hljs-string">'X-CSRF-TOKEN'</span>);

        <span class="hljs-keyword">if</span> (! $token &amp;&amp; $header = $request-&gt;header(<span class="hljs-string">'X-XSRF-TOKEN'</span>)) {
            <span class="hljs-keyword">try</span> {
                $token = CookieValuePrefix::remove(<span class="hljs-keyword">$this</span>-&gt;encrypter-&gt;decrypt($header, <span class="hljs-built_in">static</span>::serialized()));
            } <span class="hljs-keyword">catch</span> (DecryptException $e) {
                $token = <span class="hljs-string">''</span>;
            }
        }

        <span class="hljs-keyword">return</span> $token;
    }
</code></pre>
<ol start="2">
<li>Cast both request token and session to a string and then use the PHP built-in hash_equals to compare if both strings are equal using the same time. The result of this operation is always a <strong>bool (true) or (false)</strong>.</li>
</ol>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>In this article, you have learned about CSRF, how to handle and protect against it, and the behind-the-scenes of how Laravel does the verification.</p>
<p>You can read more about this in the <a target="_blank" href="https://laravel.com/docs/9.x/csrf">Laravel documentation</a>. And you can read more about <a target="_blank" href="https://www.php.net/manual/en/function.hash-equals.php">PHP hash equals in the docs here</a>.</p>
<p>Happy Coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Thunder Client – An Alternative Way to Test Restful APIs ]]>
                </title>
                <description>
                    <![CDATA[ This article will teach you an alternative approach to testing client APIs using Thunder Client, an open-source extension available on VS Code marketplace.  You will not need to download any tools to do this, since you can get it done right within VS... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/thunder-client-for-vscode/</link>
                <guid isPermaLink="false">66ba2fd554ccc2d852dc891e</guid>
                
                    <category>
                        <![CDATA[ REST API ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Testing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Visual Studio Code ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Mon, 04 Apr 2022 19:09:46 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/pexels-greg-2418664.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>This article will teach you an alternative approach to testing client APIs using Thunder Client, an open-source extension available on <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=rangav.vscode-thunder-client">VS Code marketplace</a>. </p>
<p>You will not need to download any tools to do this, since you can get it done right within VS Code.</p>
<p>The article covers the following:</p>
<ol>
<li>Intro to VS Code IDE and marketplace</li>
<li>Why use Thunder Client?</li>
<li>Advantages of Thunder Client</li>
<li>How Thunder Client works</li>
<li>How to download and install Thunder Client</li>
<li>How to launch Thunder Client</li>
<li>Collections and environment variables</li>
<li>How to make a client request</li>
<li>Preview of a sample request and response</li>
</ol>
<h2 id="heading-intro-to-vs-code-ide-and-marketplace">Intro to VS Code IDE and Marketplace</h2>
<p>VS Code is more than a code editor or IDE for so many developers. It doesn't just let you write code in your preferred language(s) – it also lets you fast track the whole development process. </p>
<p>VS Code provides a marketplace of extensions that lets you easily search and download your favorite ones from the pool of many open-source options.</p>
<h2 id="heading-why-thunder-client">Why Thunder Client?</h2>
<p>Thunder Client is an alternative to the famous Postman tool used for testing client APIs. The Thunder Client VS Code extension is lightweight and lets you test APIs on the fly within the editor.</p>
<p>You might not want to download another tool to test the APIs you're building. Instead, how about downloading an extension in VSCode that offers a wide range of functionalities like:</p>
<ul>
<li>collections, </li>
<li>environment variables, </li>
<li>support for standard HTTP verbs, </li>
<li>navigation tabs (Query, Headers, Auth, Body, Test), and </li>
<li>Support for JSON Responses</li>
</ul>
<h3 id="heading-thunder-client-vs-postman">Thunder Client vs Postman</h3>
<p>Thunder Client is lightweight and is suitable for users who want a simple user interface and fantastic user experience with zero complexity. It also runs flawlessly offline and provides documentation with markdown support 🤯.</p>
<p>Keep in mind that Postman is more robust and has a broader range of features built to industry standards. It allows a community of developers to explore the largest network of APIs, workspace, and collections all over the world. It also has features like creating teams, reporting, monitors (periodically checking for APIs performance and response), and mock servers (leverages mock servers that help simulate endpoints and their corresponding responses without a backend). </p>
<p>It's easy to create APIs because it offers support for versioning, schema types (OpenAPI 3.0- 1.0, RAML, GraphQL), and schema format (JSON, YAML). </p>
<p>Like every great tool, Postman has an up-to-date learning centre where you can find documentation to get started with the tool. Sounds interesting too, right? Well yeah 😁 both are unique and perfect for their use cases.</p>
<h2 id="heading-advantages-of-thunder-client">Advantages of Thunder Client</h2>
<p>First, it's a super fast API client extension. It creates requests to retrieve responses quickly and seamlessly. It also does not require internet access when testing APIs on your local machine.</p>
<p>It also has an intuitive and easy to use user interface. The interface is friendly and a lot easier to use as there are relatively few features on the extension compared to a tool like Postman.</p>
<p>Thunder Client has extensive API request handling. It's efficient for processing large requests at a time and does not slow down the VS Code application.</p>
<p>It also supports Visual Studio Code themes and adopts your currently configured VS Code theme.</p>
<p>Finally, Thunder Client supports collections, environment variables, GraphQL, and test scripts. It also has popular features that robust tools like Postman have. </p>
<p>In general, Thunder Client makes an excellent alternative for a small team who only need access to basic features like collections, an environment variable, and testing.</p>
<h2 id="heading-how-thunder-client-works">How Thunder Client Works</h2>
<p>If you want to use Thunder Client, you'll need to go to the VS Code marketplace to download the extension and then launch it. Once you've done that, here are a few basic things you can use the extension to do:</p>
<p><strong>Track Activity:</strong> Thunder Client keeps track of recent API requests a user has made in the past. You can also filter the activity to narrow it down to a preferred activity search. It is also called History.</p>
<p><strong>Use Collections:</strong> You can organise APIs so it's easier to access them. Collections are a group of APIs, so you can create a User collection to include APIs like create user, edit user, delete user, and so on.</p>
<p><strong>Environment Variables:</strong> With Envs, you can store credentials like tokens, base URLs, and public and private keys and then use the variables within the request body.</p>
<p><strong>Make Requests:</strong> You can specify your preferred HTTP verb to go along with the request, like POST, then the endpoint. With the request Thunder Client, there is also support for Query Parameters, HTTP Headers (Raw or Not), Authentication (None, Basic, Bearer, OAuth 2, AWS and NTLM Authentication), Body (Payload attached to individual request) and Test (you select the test type which can be a response code and set a value to assert).</p>
<p><strong>Responses:</strong> Thunder Client offers a well-crafted response section with the response body, response status, and size and time it took for the request. It also lets users add markdown supported documentation, making it even more enjoyable.</p>
<h2 id="heading-how-to-download-and-install-thunder-client">How to Download and Install Thunder Client</h2>
<p>To download Thunder Client, you can find it on VS Code marketplace. Just search for "Thunder Client" when you're prompted and then install it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Screenshot-2022-03-20-at-17.19.32.png" alt="Image" width="600" height="400" loading="lazy">
<em>Search Thunder Client On Marketplace</em></p>
<p><strong>NOTE</strong>: I have mine installed already, so the uninstall option is showing in the image.</p>
<p>Install the Thunder Client extension by clicking on the install button. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Screenshot-2022-03-20-at-17.20.56-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Install Thunder Client</em></p>
<h2 id="heading-how-to-launch-thunder-client">How to Launch Thunder Client</h2>
<p>Click on the new icon that's been added in VS Code to launch Thunder Client.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Screenshot-2022-03-20-at-19.09.50.png" alt="Image" width="600" height="400" loading="lazy">
<em>Launch Thunder Client</em></p>
<p>Then you can start using Thunder Client.</p>
<h2 id="heading-how-to-use-the-activity-tab">How to Use the Activity Tab</h2>
<p>The activity tab shows the history of your API request in recent times. You are also free to perform operations such as saving to a collection, renaming, duplicating, and more as shown in the image.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-2022-04-03-at-02.31.28.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-use-collections-and-environment-variables">How to Use Collections and Environment Variables</h2>
<p>Collections are a group of API Requests. Thunder Client lets you work with collections or create a single individual request like the "New Request" button. </p>
<p>To work with collections, click on the "Collections tab", then click on the icon the arrow points to in the image below. This shows a dropdown where you select if you want a "New collection" or have an existing collection for import.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Screenshot-2022-03-20-at-19.06.19.png" alt="Image" width="600" height="400" loading="lazy">
<em>Create &amp; Import collection</em></p>
<p>You can add environment variables by clicking the "Env" tab, then clicking on the icon the arrow points to in the image below. This shows a dropdown to set up the env variables for requests. You also get to import existing variables.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Screenshot-2022-03-20-at-19.06.46.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-make-a-client-request">How to Make a Client Request</h2>
<p>Depending on the type of Request, Thunder Client offers a list of HTTP VERBS for requests such as <strong>GET, POST, PUT, DELETE,</strong> and <strong>PATCH</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Screenshot-2022-03-20-at-19.36.24.png" alt="Image" width="600" height="400" loading="lazy">
<em>HTTP Verbs in Thunder Client</em></p>
<p>There is also support for Query parameters, Headers, Authorization, Body and Tests. At the time of writing, there is no support for file attachments for requests yet. You can check the upcoming release notes <a target="_blank" href="https://github.com/rangav/thunder-client-support/issues/282">here</a>.</p>
<p><strong>Query Parameters</strong> allow you to append query parameters to the request.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-2022-04-03-at-02.34.19.png" alt="Image" width="600" height="400" loading="lazy">
<em>Query Params</em></p>
<p><strong>Headers</strong> let you set HTTP headers like authorization, content-type, origin, user-agent, accept-language, referrer, and so on. </p>
<p>If you want any headers to be optional, just make sure to leave them unchecked for the request. There is also an autocomplete suggestion enabled for your preferred type of header.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-2022-04-03-at-02.41.55.png" alt="Image" width="600" height="400" loading="lazy">
<em>Http Headers</em></p>
<p>To access resources, you need to have tokens that authenticate them. With Thunder Client, the Auth tab lets you select your preferred type of Auth and add credentials. </p>
<p>In my case, I choose Bearer; then, I have a token pasted into the text area and an auto-generated token prefix for the request.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-2022-04-03-at-02.45.46.png" alt="Image" width="600" height="400" loading="lazy">
<em>Authentication</em></p>
<p>You can include a payload when making a request. To add the payload, select the Body tab, and you will see different data formats supported by the extension.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot-2022-04-03-at-02.53.24.png" alt="Image" width="600" height="400" loading="lazy">
<em>Request Payload</em></p>
<h2 id="heading-sample-request-and-response">Sample Request and Response</h2>
<p>The image below shows a sample request with query parameters and a sample JSON response.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Screenshot-2022-03-20-at-20.20.52.png" alt="Image" width="600" height="400" loading="lazy">
<em>Sample Request &amp; Response</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Yaaay, excited to have you hooked till the end. I hope you have learned how to search the VS Code marketplace for extensions and can start making API Requests with Thunder Client. </p>
<p>Massive shout out to the creator <a target="_blank" href="https://www.freecodecamp.org/news/p/7b47d7f1-beed-41b6-a792-6cbf0c8abf52/twitter.com/ranga_vadhineni">@Rangav</a> on Twitter for the superb extension. </p>
<p>Follow me on <a target="_blank" href="https://twitter.com/bigdevlarry">twitter</a> and also share if you find it useful.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Set Up reCAPTCHA v3 in a Laravel Project ]]>
                </title>
                <description>
                    <![CDATA[ In this article, you'll learn how to set up reCAPTCHA v3 in your Laravel project. This can be a bit tricky, so I'll help you simplify the process here.  What is reCaptcha? reCaptcha is a Google service provided for free that helps you protect your we... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-setup-recaptcha-v3-in-laravel/</link>
                <guid isPermaLink="false">66ba2fbac346e93df556afff</guid>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Mon, 20 Sep 2021 22:26:01 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/09/pexels-davis-sanchez-1727004.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this article, you'll learn how to set up reCAPTCHA v3 in your Laravel project. This can be a bit tricky, so I'll help you simplify the process here. </p>
<h2 id="heading-what-is-recaptcha">What is reCaptcha?</h2>
<p><a target="_blank" href="https://developers.google.com/recaptcha/">reCaptcha</a> is a Google service provided for free that helps you protect your websites from spam and malicious attacks. </p>
<p>The new version, V3, has many improvements over previous versions thanks to the new captcha challenges. It returns a score and analytics you can use to take appropriate action for your website.</p>
<p>Here's what the previous version of reCaptcha looks like – but as of the latest release (v3), reCaptcha has changed a lot and has a better user experience.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/11/newCaptchaAnchor.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Previous reCaptcha Version</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/11/Screenshot-2020-11-26-at-04.11.28.png" alt="Image" width="600" height="400" loading="lazy">
<em>Previous reCaptcha Version</em></p>
<h2 id="heading-what-youll-learn">What you'll learn</h2>
<p>By the end of this article, you'll have learned the following:</p>
<ol>
<li>How to integrate the reCaptcha v3 into your Laravel project</li>
<li>How to setup a Google reCaptcha admin dashboard</li>
<li>How to view your website reCaptcha scores and analytics to help you make better security decisions</li>
</ol>
<h2 id="heading-how-to-setup-recaptcha-in-a-laravel-project">How to Setup reCaptcha in a Laravel Project</h2>
<p>You can follow these simple steps to get reCaptcha set up on your project.</p>
<ol>
<li>Install this <a target="_blank" href="https://laravel.com/docs/8.x/installation">laravel project</a> if you haven't done so yet</li>
<li>In the terminal, pull the open-source package into your project with composer.</li>
</ol>
<pre><code>composer <span class="hljs-built_in">require</span> biscolab/laravel-recaptcha
</code></pre><ol start="3">
<li>Publish the <code>recaptcha.php</code> with this command:</li>
</ol>
<pre><code class="lang-php">php artisan vendor:publish --provider=<span class="hljs-string">"Biscolab\ReCaptcha\ReCaptchaServiceProvider"</span>
</code></pre>
<p>This will create a file in the config directory, called <code>config\recaptcha.php</code>, where we will add more reCaptcha configurations.</p>
<ol start="4">
<li><a target="_blank" href="https://www.google.com/recaptcha/admin/create">Visit this link</a> to create a reCaptcha admin account for yourself.</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/reCAPTCHA-2021-07-23-10-59-07.png" alt="Image" width="600" height="400" loading="lazy">
<em>Register reCaptcha v3</em></p>
<p>To create the reCaptcha admin, you can do the following:</p>
<ul>
<li>Add your site name to the label – <code>localhost</code>  or <code>examplesite.com</code></li>
<li>Select v3 as the reCaptcha type</li>
<li>Include domains in the domain section (<code>localhost</code> or <code>examplesite.com</code>)</li>
<li>Add the owner's email address to the owner's section</li>
<li>Check the "accept terms and service" box </li>
</ul>
<p>Just a note – the localhost is for the sole purpose of developing locally. As such, it should be updated before moving to a production environment.</p>
<ol start="5">
<li>Add the reCaptcha to your site</li>
</ol>
<p>Click the submit button and save your secret keys. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/reCAPTCHA-2021-07-23-11-16-17.png" alt="Image" width="600" height="400" loading="lazy">
<em>Adding reCaptcha to your site within the .env</em></p>
<ol start="6">
<li>Add the site keys to the <code>.env</code> file of your project:</li>
</ol>
<pre><code class="lang-php">RECAPTCHA_SITE_KEY=ADD_YOUR_SITE_KEY
RECAPTCHA_SECRET_KEY=ADD_YOUR_SECRET_KEY
RECAPTCHA_SITE=https:<span class="hljs-comment">//www.google.com/recaptcha/admin/</span>
</code></pre>
<p>Since you have made changes to the <code>.env</code>, it's best to clear all cached configurations so that the new changes take effect. Use <code>php artisan optimize:clear</code> in your terminal.</p>
<ol start="7">
<li>Within the <code>config &gt; recaptcha.php</code> file, update the property of the version to V3. It's also important to note that the <code>api_site_key</code> and <code>api_secret_key</code> generated via the admin dashboard will be referenced from what we set in the .env file of the project.</li>
</ol>
<pre><code class="lang-php"><span class="hljs-keyword">return</span> [
    <span class="hljs-string">'version'</span>                      =&gt; <span class="hljs-string">'v3'</span>
]
</code></pre>
<p>You can now head over to the analytics page of the reCaptcha admin to view how well your site is performing, view your scores, and make decisions when you're in a production environment.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/reCAPTCHA-2021-07-24-10-27-04-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>reCaptcha analytics page</em></p>
<p>The below image shows that reCaptcha has been implemented.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/Screenshot-2021-09-19-at-15.37.00.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>At the end of this article, I hope you'll find it easier to set up reCaptcha and that you'll have a better understanding of what it's all about. Now you should be able to set up the most recent version within your Laravel project.</p>
<h3 id="heading-resources">Resources</h3>
<ul>
<li>What is <a target="_blank" href="https://developers.google.com/recaptcha/">reCaptcha</a>?</li>
<li>Laravel reCaptcha <a target="_blank" href="https://github.com/biscolab/laravel-recaptcha">repo</a></li>
<li>Laravel reCaptcha <a target="_blank" href="https://laravel-recaptcha-docs.biscolab.com/docs/configuration">docs</a> </li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a GraphQL Server with Laravel GraphQL and Test It with Postman ]]>
                </title>
                <description>
                    <![CDATA[ GraphQL is a query language for your API. It simplifies the process of requesting the server by providing convenient ways to query objects.  For instance, if you're using a REST API and you need a list of books, you might hit the GET /books/list endp... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-graphql-server-with-laravel/</link>
                <guid isPermaLink="false">66ba2fb0de9370f66eeb0a99</guid>
                
                    <category>
                        <![CDATA[ api ]]>
                    </category>
                
                    <category>
                        <![CDATA[ GraphQL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Tue, 13 Jul 2021 07:54:34 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/07/ben-4wxWBy8Jo1I-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="https://graphql.org/">GraphQL</a> is a query language for your API. It simplifies the process of requesting the server by providing convenient ways to query objects. </p>
<p>For instance, if you're using a REST API and you need a list of books, you might hit the <code>GET /books/list</code> endpoint for all books. Then if you need a specific book by ID, you would hit <code>GET /book?id={id}</code>, which means you'll be making multiple requests to the server.</p>
<p>But GraphQL does something called declarative data fetching, where you can ask for what you want and get a predictable result in a single request. </p>
<p>Awesome right? Let's see how it all works.</p>
<h3 id="heading-what-we-will-be-learning">What we will be learning?</h3>
<p>In this article, you'll learn the basics of GraphQL by using the <a target="_blank" href="https://github.com/rebing/graphql-laravel">Laravel GraphQL package</a> to build a server that does the following:</p>
<ol>
<li>Register users </li>
<li>Fetch all users</li>
<li>Get a user by ID</li>
<li>Fetch all posts</li>
<li>Fetch all posts with user relationships</li>
<li>Finally, as a bonus, you'll also learn how to use the super awesome Postman tool to run your query and get a real-time response</li>
</ol>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Here are a few things you'll need for this tutorial:</p>
<ol>
<li>A local server (<a target="_blank" href="https://www.apachefriends.org/download.html">XAMPP</a> or <a target="_blank" href="https://www.wampserver.com/en/download-wampserver-64bits/">WAMP</a>)</li>
<li>A code editor (<a target="_blank" href="https://www.sublimetext.com/3">Sublime Text</a>,  <a target="_blank" href="https://atom.io/">VS</a> <a target="_blank" href="https://code.visualstudio.com/download">Code</a>, or <a target="_blank" href="https://atom.io/">Atom</a>)</li>
<li>A version control system (<a target="_blank" href="https://git-scm.com/downloads">Git</a>)</li>
<li>A dependency Manager (<a target="_blank" href="https://getcomposer.org/download/">Composer</a>)</li>
<li>The <a target="_blank" href="https://github.com/rebing/graphql-laravel">Laravel GraphQL package</a></li>
</ol>
<h2 id="heading-graphql-basics">GraphQL Basics</h2>
<p>Before we get started, let's go over some GraphQL fundamentals.</p>
<h3 id="heading-what-is-a-graphql-schema">What is a GraphQL Schema?</h3>
<p>A GraphQL schema describes queries, mutations, and types associated with it:</p>
<pre><code class="lang-php">type User {
    id: ID !
    name : <span class="hljs-keyword">String</span> !
    email : <span class="hljs-keyword">String</span> !
    age : <span class="hljs-keyword">Int</span>
    hobbies: [<span class="hljs-keyword">String</span>]
    created_at : DateTime 
    updated_at : DateTime
}
</code></pre>
<p>In the code above, the exclamation mark on column names such as <code>id</code>, <code>name</code>, and <code>email</code> means that they are required fields.</p>
<p>You can also define various data types such as <code>Int</code>, <code>String</code>, and so on. You can also include list types and define the data type it should contain like with <code>hobbies</code>. </p>
<h3 id="heading-what-are-graphql-queries">What are GraphQL Queries?</h3>
<p>GraphQL makes it convenient to interact with data on an object. You use methods to ask for specific fields on objects and then get the expected results:</p>
<pre><code class="lang-php">{
  user {
    name
  }
}
</code></pre>
<pre><code class="lang-php">{
  <span class="hljs-string">"data"</span>: {
    <span class="hljs-string">"user"</span>: {
      <span class="hljs-string">"name"</span>: <span class="hljs-string">"John doe"</span>
    }
  }
}
</code></pre>
<h3 id="heading-what-are-graphql-resolvers">What are GraphQL Resolvers?</h3>
<p>Every time you request data from a GraphQL server, it gets <code>resolved</code>.</p>
<p>Resolvers contain arguments such as an <code>object</code>, <code>args</code>, <code>context</code>, and <code>info</code>. You'll see how resolvers work while building this project.</p>
<h2 id="heading-how-to-get-started-with-graphql">How to Get Started with GraphQL</h2>
<h3 id="heading-installation">Installation</h3>
<p>Set up a Laravel environment by running this command in the terminal:</p>
<pre><code class="lang-php">composer create-project laravel/laravel graphql-laravel
</code></pre>
<p>If you don't have composer installed, you can get it from <a target="_blank" href="https://getcomposer.org/">here</a>.</p>
<p>Install the open-source <a target="_blank" href="https://github.com/rebing/graphql-laravel">graphql-laravel server</a> package:</p>
<pre><code class="lang-php">composer <span class="hljs-keyword">require</span> rebing/graphql-laravel
</code></pre>
<p>Once the installation is finished, publish <code>config/graphql.php</code>:</p>
<pre><code class="lang-php">php artisan vendor:publish --provider=<span class="hljs-string">"Rebing\GraphQL\GraphQLServiceProvider"</span>
</code></pre>
<p>And start the development server with <code>php artisan serve</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/Screenshot-2021-05-08-at-16.14.36.png" alt="Image" width="600" height="400" loading="lazy">
<em>The Laravel homepage</em></p>
<h3 id="heading-how-to-create-the-migration-controllers-and-resource">How to Create the Migration, Controllers, and Resource</h3>
<h4 id="heading-post">Post</h4>
<p>In this section, you'll create a relationship between users and posts.</p>
<p>To do this, you'll need to create models where you define the relationship between the entities, create migrations, and define database schemas.</p>
<pre><code class="lang-php">php artisan make:model Post -mcr
</code></pre>
<p>In <code>app/Models/User</code>, create a <code>hasMany</code> relationship between users and posts:</p>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">posts</span>(<span class="hljs-params"></span>)
</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;hasMany(Post::class);
}
</code></pre>
<p>And in <code>app/models/Post</code>, define a relationship to map users to posts:</p>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">user</span>(<span class="hljs-params"></span>)
</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;belongsTo(User::class);
}
</code></pre>
<h3 id="heading-how-to-create-the-migration">How to Create the Migration</h3>
<p>In this section you'll create the migration.</p>
<p>Laravel already ships with a default User migration. All you need to do now is add a migration for posts:</p>
<pre><code class="lang-php">php artisan make:migration create_post_table
</code></pre>
<p>This creates a migration file with the <code>database/migrations</code> direction. Within the migration file, define the schema:</p>
<pre><code class="lang-php">Schema::create(<span class="hljs-string">'posts'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) </span>{
            $table-&gt;id();
             $table-&gt;integer(<span class="hljs-string">'user_id'</span>)-&gt;unsigned();
            $table-&gt;string(<span class="hljs-string">'title'</span>);
            $table-&gt;text(<span class="hljs-string">'comment'</span>);
            $table-&gt;timestamps();
        });
</code></pre>
<p>Next, modify the existing <code>.env</code> to name the database and establish a connection:</p>
<pre><code class="lang-php">DB_CONNECTION=mysql
DB_HOST=<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>
DB_PORT=<span class="hljs-number">3306</span>
DB_DATABASE=graphql-laravel
DB_USERNAME=root
DB_PASSWORD=
</code></pre>
<p>Run the migrate command to create the <code>User</code> and <code>Post</code> tables:</p>
<pre><code class="lang-php"> php artisan migrate
</code></pre>
<p>You can generate random records for the <code>User</code> and <code>Post</code> tables using Laravel factories.</p>
<p>Since Laravel ships with a default <code>User</code> factory, you can use that and focus on creating a <code>Post</code> factory.</p>
<h3 id="heading-how-to-create-a-post-factory">How to Create a Post Factory</h3>
<pre><code class="lang-php">php artisan make:factory PostFactory
</code></pre>
<p>Once <code>PostFactory</code> gets created within the <code>database &gt; factories</code> directory, you'll have to define the column names and the fakers you need within the <code>definition method</code>:</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">Str</span>;


<span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">definition</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">'user_id'</span> =&gt; rand(<span class="hljs-number">1</span>,<span class="hljs-number">5</span>),
            <span class="hljs-string">'title'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;faker-&gt;name(),
            <span class="hljs-string">'comment'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;faker-&gt;realText(<span class="hljs-number">180</span>)
        ];
    }
</code></pre>
<h3 id="heading-how-to-make-the-database-seeder">How to Make the Database Seeder</h3>
<p>Within the seeder class, create an execution instance for both <code>User</code> and <code>Post</code> factories.</p>
<p>This will create five users and five posts with corresponding <code>user_id</code>'s:</p>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">run</span>(<span class="hljs-params"></span>)
    </span>{
        \App\Models\User::factory(<span class="hljs-number">5</span>)-&gt;create();

        \App\Models\Post::factory(<span class="hljs-number">5</span>)-&gt;create();
    }
</code></pre>
<p>Then run the artisan seeder command:</p>
<pre><code class="lang-php">php artisan db:seed
</code></pre>
<p>Once you run that command in the terminal, check the database tables (<code>User</code> and <code>Post</code>):</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/Screenshot-2021-05-26-at-02.40.17.png" alt="Image" width="600" height="400" loading="lazy">
<em>Post table</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/Screenshot-2021-05-25-at-18.32.11.png" alt="Image" width="600" height="400" loading="lazy">
<em>User table</em></p>
<h3 id="heading-how-to-create-a-user-query">How to Create a User Query</h3>
<p>As of the time of writing this article, the Laravel GraphQL package doesn't support creating a scaffold for queries via the terminal.</p>
<p>So add the following to <code>app &gt; GraphQL &gt; Type &gt; UserType.php</code>:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>\<span class="hljs-title">Definition</span>\<span class="hljs-title">Type</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Rebing</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Type</span> <span class="hljs-title">as</span> <span class="hljs-title">GraphQLType</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserType</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">GraphQLType</span>
</span>{
    <span class="hljs-keyword">protected</span> $attributes = [
        <span class="hljs-string">'name'</span>          =&gt; <span class="hljs-string">'User'</span>,
        <span class="hljs-string">'description'</span>   =&gt; <span class="hljs-string">'A user'</span>,
        <span class="hljs-string">'model'</span>         =&gt; User::class,
    ];

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fields</span>(<span class="hljs-params"></span>): <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">'id'</span> =&gt; [
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::int()),
                <span class="hljs-string">'description'</span> =&gt; <span class="hljs-string">'The id of the user'</span>,
            ],
            <span class="hljs-string">'name'</span> =&gt; [
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::string()),
                <span class="hljs-string">'description'</span> =&gt; <span class="hljs-string">'The name of user'</span>,
            ],
            <span class="hljs-string">'email'</span> =&gt; [
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::string()),
                <span class="hljs-string">'description'</span> =&gt; <span class="hljs-string">'The email of user'</span>
            ],
        ];
    }
}
</code></pre>
<p>In the code snippet above, you add the namespace you need to the <code>User</code> model. You also include a <code>protected $attributes array</code> that describes the model.</p>
<p>You also added a public <code>field</code> function that returns an array.</p>
<p>Within this function, you define the schema to include columns you specified in the user table <code>(id, name, email)</code>.</p>
<p><code>Type::nonNull(Type::string())</code> is the exclamation mark indicating the required fields and string data type.</p>
<h3 id="heading-how-to-add-a-type-to-the-config">How to Add a Type to the Config</h3>
<p>Add the <code>UserType</code> to the config file you created earlier: <code>app &gt; config &gt; graphql.php</code>:</p>
<pre><code class="lang-php"><span class="hljs-string">'types'</span> =&gt; [
        App\GraphQL\Type\UserType::class
    ],
</code></pre>
<h3 id="heading-how-to-define-the-user-query">How to Define the User Query</h3>
<p>Next, you'll need to define a query that returns the <code>UserType</code> or a list. You also need to specify the arguments you'll use within the resolve method:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>\<span class="hljs-title">Definition</span>\<span class="hljs-title">Type</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Rebing</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Type</span> <span class="hljs-title">as</span> <span class="hljs-title">GraphQLType</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserType</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">GraphQLType</span>
</span>{
    <span class="hljs-keyword">protected</span> $attributes = [
        <span class="hljs-string">'name'</span>          =&gt; <span class="hljs-string">'User'</span>,
        <span class="hljs-string">'description'</span>   =&gt; <span class="hljs-string">'A user'</span>,
        <span class="hljs-string">'model'</span>         =&gt; User::class,
    ];

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">type</span>(<span class="hljs-params"></span>): <span class="hljs-title">Type</span>
    </span>{
        <span class="hljs-keyword">return</span> Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type(<span class="hljs-string">'User'</span>))));
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">args</span>(<span class="hljs-params"></span>): <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">'id'</span> =&gt; [
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::int()),
                <span class="hljs-string">'description'</span> =&gt; <span class="hljs-string">'The id of the user'</span>,
            ],
            <span class="hljs-string">'name'</span> =&gt; [
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::string()),
                <span class="hljs-string">'description'</span> =&gt; <span class="hljs-string">'The name of user'</span>,
            ],
            <span class="hljs-string">'email'</span> =&gt; [
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::string()),
                <span class="hljs-string">'description'</span> =&gt; <span class="hljs-string">'The email of user'</span>,
            ]
        ];
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">resolve</span>(<span class="hljs-params">$root, $args</span>)
    </span>{        
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>($args[<span class="hljs-string">'id'</span>])) {
            <span class="hljs-keyword">return</span> User::whereId($args[<span class="hljs-string">'id'</span>])-&gt;get();
        }

        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>($args[<span class="hljs-string">'name'</span>])) {
            <span class="hljs-keyword">return</span> User::whereName($args[<span class="hljs-string">'name'</span>])-&gt;get();
        }

        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>($args[<span class="hljs-string">'email'</span>])) {
            <span class="hljs-keyword">return</span> User::whereEmail($args[<span class="hljs-string">'email'</span>])-&gt;get();
        }

        <span class="hljs-keyword">return</span> User::all();
    }
}
</code></pre>
<p>In the snippet above, you use the required namespace the package ships with together with <code>App\Models\User</code>.</p>
<p>You also extend the <code>GraphQLType</code> from the Laravel package, and define the <code>attributes</code> as a protected array.</p>
<p>The <code>args</code> method returns an ID, name, and email from the <code>User</code> model.</p>
<p>The resolve method is used to retrieve the data from the database. If there are <code>args</code>, then the <code>if</code> block gets executed and helps you filter based on user requests.</p>
<p>Otherwise, all the data from the <code>User</code> model is retrieved.</p>
<h3 id="heading-how-to-add-a-query-to-the-config">How to Add a Query to the Config</h3>
<p>Add the following query to the <code>app &gt; config &gt; graphql.php</code> configurations file:</p>
<pre><code class="lang-php"><span class="hljs-string">'schemas'</span> =&gt; [
        <span class="hljs-string">'default'</span> =&gt; [
            <span class="hljs-string">'query'</span> =&gt; [
                App\GraphQL\Query\UsersQuery::class,
            ],
            <span class="hljs-string">'mutation'</span> =&gt; [
                <span class="hljs-comment">// ExampleMutation::class,</span>
            ],
            <span class="hljs-string">'types'</span> =&gt; [
                <span class="hljs-comment">// ExampleType::class,</span>
            ],
            <span class="hljs-string">'middleware'</span> =&gt; [],
            <span class="hljs-string">'method'</span> =&gt; [<span class="hljs-string">'get'</span>, <span class="hljs-string">'post'</span>],
        ],
    ],
</code></pre>
<p>You should now be able to query data from this endpoint: <a target="_blank" href="http://localhost:8000/graphql">http://localhost:8000/graphql</a>.</p>
<p>And in case you're curious, <code>/graphql</code> is the prefix for the route.</p>
<h3 id="heading-how-to-query-to-fetch-all-users">How to Query to Fetch all Users</h3>
<p>For this query:</p>
<pre><code class="lang-php">query {
    users {
        id, name , email
    }
}
</code></pre>
<p>Here's the expected output with Postman:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/Screenshot-2021-05-26-at-01.13.22.png" alt="Image" width="600" height="400" loading="lazy">
<em>Fetch all Users</em></p>
<h3 id="heading-how-to-create-a-post-relationship-with-the-user">How to Create a Post Relationship with the User</h3>
<p>Now you need to define a <code>PostType</code>.</p>
<p>This approach follows what you defined earlier for <code>UserType</code>.</p>
<p>Navigate to <code>app &gt; Type &gt; PostType.php</code> and add the following:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">Post</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>\<span class="hljs-title">Definition</span>\<span class="hljs-title">Type</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Rebing</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Type</span> <span class="hljs-title">as</span> <span class="hljs-title">GraphQLType</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PostType</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">GraphQLType</span>
</span>{
    <span class="hljs-keyword">protected</span> $attributes = [
        <span class="hljs-string">'name'</span>          =&gt; <span class="hljs-string">'Post'</span>,
        <span class="hljs-string">'description'</span>   =&gt; <span class="hljs-string">'A post'</span>,
        <span class="hljs-string">'model'</span>         =&gt; Post::class,
    ];

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">args</span>(<span class="hljs-params"></span>): <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">'id'</span> =&gt; [
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::int()),
                <span class="hljs-string">'description'</span> =&gt; <span class="hljs-string">'The id of the post'</span>,
            ],
            <span class="hljs-string">'title'</span> =&gt; [
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::string()),
                <span class="hljs-string">'description'</span> =&gt; <span class="hljs-string">'The title of post'</span>,
            ],
        ];
    }
}
</code></pre>
<p><code>Post</code> follows the specification defined for <code>User</code>. Here you also used the namespace of the query, and also used the <code>Post</code> model.</p>
<p>With the code above, you extend the Query on the <code>PostQuery</code> class and set the <code>$attributes</code> array to be protected. And you have a <code>fields</code> function that returns and array with the ID, title, and comment.</p>
<p>Finally, you have a <code>type</code> within the <code>args</code> function that shows their various data types <code>int</code> or <code>string</code> with a description that tells you what they do at a glance.</p>
<h3 id="heading-how-to-create-a-postsquery">How to Create a PostsQuery</h3>
<p>Add the following to <code>app &gt; GraphQL &gt; Query &gt; PostsQuery.php</code>:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span> 

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Query</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Closure</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">Post</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Rebing</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">GraphQL</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>\<span class="hljs-title">Definition</span>\<span class="hljs-title">ResolveInfo</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>\<span class="hljs-title">Definition</span>\<span class="hljs-title">Type</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Rebing</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Query</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PostsQuery</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Query</span>
</span>{
    <span class="hljs-keyword">protected</span> $attributes = [
        <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'posts'</span>,
    ];

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">type</span>(<span class="hljs-params"></span>): <span class="hljs-title">Type</span>
    </span>{
        <span class="hljs-keyword">return</span> Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type(<span class="hljs-string">'Post'</span>))));
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">args</span>(<span class="hljs-params"></span>): <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">'id'</span> =&gt; [
                <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'id'</span>, 
                <span class="hljs-string">'type'</span> =&gt; Type::int(),
            ],
            <span class="hljs-string">'title'</span> =&gt; [
                <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'title'</span>, 
                <span class="hljs-string">'type'</span> =&gt; Type::string(),
            ]
        ];
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">resolve</span>(<span class="hljs-params">$root, $args</span>)
    </span>{        
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>($args[<span class="hljs-string">'id'</span>])) {
            <span class="hljs-keyword">return</span> Post::whereId($args[<span class="hljs-string">'id'</span>])-&gt;get();
        }

        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>($args[<span class="hljs-string">'title'</span>])) {
            <span class="hljs-keyword">return</span> Post::whereTitle($args[<span class="hljs-string">'title'</span>])-&gt;get();
        }

        <span class="hljs-keyword">return</span> Post::all();
    }
}
</code></pre>
<p>In the code above, you use the resolve method to retrieve data from the database like I mentioned earlier.</p>
<p>If there are <code>args</code>, then the <code>if</code> block gets executed and helps you filter based on the user request. Otherwise, all the data from the <code>Post</code> model is returned.</p>
<h3 id="heading-how-to-add-postsquery-and-posttype-to-config">How to Add PostsQuery and PostType to Config</h3>
<pre><code class="lang-php"><span class="hljs-string">'schemas'</span> =&gt; [
        <span class="hljs-string">'default'</span> =&gt; [
            <span class="hljs-string">'query'</span> =&gt; [
                App\GraphQL\Query\UsersQuery::class,
                App\GraphQL\Query\PostsQuery::class
            ],
            <span class="hljs-string">'mutation'</span> =&gt; [
                <span class="hljs-comment">// ExampleMutation::class,</span>
            ],
            <span class="hljs-string">'types'</span> =&gt; [
                <span class="hljs-comment">// ExampleType::class,</span>
            ],
            <span class="hljs-string">'middleware'</span> =&gt; [],
            <span class="hljs-string">'method'</span> =&gt; [<span class="hljs-string">'get'</span>, <span class="hljs-string">'post'</span>],
        ],
    ],
</code></pre>
<pre><code class="lang-php"><span class="hljs-string">'types'</span> =&gt; [
        App\GraphQL\Type\UserType::class,
        App\GraphQL\Type\PostType::class
    ],
</code></pre>
<p>Now you can use the following query to get all posts:</p>
<pre><code class="lang-php">query{
    posts{
        id
        user_id
        title
        comment
    }
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/Screenshot-2021-05-26-at-03.00.41.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image of Fetch all post</em></p>
<p>You can also fetch users with post relationships with this query:</p>
<pre><code class="lang-php">query{
    users{
        id 
        name
        posts {
            title
        }
    }
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/Screenshot-2021-07-11-at-15.40.05.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image to fetch users with post relationship</em></p>
<h3 id="heading-how-to-create-a-mutation">How to Create a Mutation</h3>
<p>Now you'll set up a mutation to create a user. This mutation will help with operations that involve modifying state on the server.</p>
<p>In your case you'll be mutating the state of the server by creating a user.</p>
<p>Create a mutation folder within the app directory, <code>app &gt; Mutation &gt; CreateUserMutation.php</code>.</p>
<p>Then add the following code to <code>CreateUserMutation.php</code>:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Mutation</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Closure</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>\<span class="hljs-title">Definition</span>\<span class="hljs-title">Type</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">GraphQL</span>\<span class="hljs-title">Type</span>\<span class="hljs-title">Definition</span>\<span class="hljs-title">ResolveInfo</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Rebing</span>\<span class="hljs-title">GraphQL</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Mutation</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CreateUserMutation</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Mutation</span>
</span>{
    <span class="hljs-keyword">protected</span> $attributes = [
        <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'users'</span>
    ];

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">type</span>(<span class="hljs-params"></span>): <span class="hljs-title">Type</span>
    </span>{
        <span class="hljs-keyword">return</span> Type::nonNull(GraphQL::type(<span class="hljs-string">'User'</span>));
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">args</span>(<span class="hljs-params"></span>): <span class="hljs-title">array</span>
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">'name'</span> =&gt; [<span class="hljs-string">'
                name'</span> =&gt; <span class="hljs-string">'name'</span>, 
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::string()),
            ],
            <span class="hljs-string">'email'</span> =&gt; [<span class="hljs-string">'
                name'</span> =&gt; <span class="hljs-string">'email'</span>, 
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::string()),
            ],
            <span class="hljs-string">'password'</span> =&gt; [
                <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'password'</span>, 
                <span class="hljs-string">'type'</span> =&gt; Type::nonNull(Type::string()),
            ]
        ];
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">resolve</span>(<span class="hljs-params">$root, $args, $context, ResolveInfo $resolveInfo, <span class="hljs-built_in">Closure</span> $getSelectFields</span>)
    </span>{
        <span class="hljs-keyword">return</span> User::firstOrCreate(
            [   <span class="hljs-string">'email'</span> =&gt; $args[<span class="hljs-string">'email'</span>]],
            [   <span class="hljs-string">'name'</span> =&gt; $args[<span class="hljs-string">'name'</span>],
                <span class="hljs-string">'password'</span> =&gt; bcrypt($args[<span class="hljs-string">'password'</span>])
            ]);
    }
}
</code></pre>
<p>The <code>resolve</code> method helps users of the application sign up and create their record. <code>resolve</code> accepts <code>args</code> as a parameter and then uses the <code>firstOrCreate</code> method to ensure all users registering have a unique identifier, in this case, their email address.</p>
<p>In the config, you'll also need to include the mutation you just created:</p>
<pre><code class="lang-php"><span class="hljs-string">'schemas'</span> =&gt; [
        <span class="hljs-string">'default'</span> =&gt; [
            <span class="hljs-string">'query'</span> =&gt; [
                App\GraphQL\Query\UsersQuery::class,
                App\GraphQL\Query\PostsQuery::class
            ],
            <span class="hljs-string">'mutation'</span> =&gt; [
                App\GraphQL\Mutation\CreateUserMutation::class,
            ],
            <span class="hljs-string">'types'</span> =&gt; [],
            <span class="hljs-string">'middleware'</span> =&gt; [],
            <span class="hljs-string">'method'</span> =&gt; [<span class="hljs-string">'get'</span>, <span class="hljs-string">'post'</span>],
        ],
    ],
</code></pre>
<p>And here's how to create a user:</p>
<pre><code class="lang-php">mutation{
    users(name : <span class="hljs-string">"John Doe"</span>, email : <span class="hljs-string">"Johndoe@gmail.com"</span>, password : <span class="hljs-string">"John1234"</span>){
        id
        name
    }
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/Screenshot-2021-05-26-at-03.50.14.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image of user creation</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Congrats! You've successfully built a GraphQL server using Laravel, and ran queries with Postman to get responses. Now that you know the basics of GraphQL, I hope you use it in your projects going forward.</p>
<p>All the code in this tutorial is available on <a target="_blank" href="https://github.com/LarrySul/GraphQL-Laravel">GitHub</a>, which also includes the Postman collection.</p>
<h3 id="heading-resources">Resources</h3>
<ul>
<li><a target="_blank" href="https://graphql.org/">GraphQL website</a> </li>
<li><a target="_blank" href="https://github.com/rebing/graphql-laravel">Laravel GraphQL</a></li>
<li><a target="_blank" href="https://www.apollographql.com/blog/tooling/graphql-ide/how-to-use-graphql-with-postman/">How to use GraphQL with Postman</a></li>
<li></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Install the AWS Elastic Beanstalk CLI on a Mac ]]>
                </title>
                <description>
                    <![CDATA[ Elastic Beanstalk is an orchestration service that allows users on the AWS platform to deploy web applications easily. It caters to any setup you might need to run an application in the cloud.  Orchestration simply means that it automates the workflo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/install-elastic-bean-cli-on-mac/</link>
                <guid isPermaLink="false">66ba2fc62d069f084485f262</guid>
                
                    <category>
                        <![CDATA[ AWS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cloud Computing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data ]]>
                    </category>
                
                    <category>
                        <![CDATA[ deployment ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Thu, 14 Jan 2021 16:34:19 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5ff9a7b475d5f706921cae6e.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Elastic Beanstalk is an orchestration service that allows users on the AWS platform to deploy web applications easily. It caters to any setup you might need to run an application in the cloud. </p>
<p>Orchestration simply means that it automates the workflow processes that occurs in order to deliver resources as a service on the cloud.</p>
<p>In this tutorial, we will be walking through the simple steps to set Elastic Beanstalk up locally. Setting it up locally means that we will be able to interact directly with AWS from the terminal and push our deployed applications to the cloud via the commands provided by EB .</p>
<h2 id="heading-benefits-of-elastic-beanstalk">Benefits of Elastic Beanstalk</h2>
<p>Elastic Beanstalk allows your data to persist after the elastic cloud compute instance is terminated. Data stored on the volume are still accessible.</p>
<p>Also, it helps you avoid component failure by offering high availability and durability. </p>
<h2 id="heading-how-to-install-the-elastic-beanstalk-cli">How to Install the Elastic Beanstalk CLI</h2>
<p>The Elastic Beanstalk CLI is a command line interface that allows users to create, setup, and manage processes on Elastic Beanstalk.</p>
<p>To install EB in our local environment, we need to check out the open-source <a target="_blank" href="https://github.com/aws/aws-elastic-beanstalk-cli-setup">aws-elastic-beanstalk-cli-setup</a> project. There we'll find installation guides to help with the process.</p>
<h3 id="heading-step-1">Step 1:</h3>
<p>Clone the repository into our local environment. If you don't have a Github account, you can sign up <a target="_blank" href="https://www.freecodecamp.org/news/p/8ffef46d-0fe6-4768-8ccd-f8743b0008d1/github.com">here</a>.</p>
<pre><code class="lang-github">git clone https://github.com/aws/aws-elastic-beanstalk-cli-setup.git
</code></pre>
<h3 id="heading-step-2">Step 2:</h3>
<p>In this section we have to download zlib and configure it. Zlib is a library used for compression and decompression. EB leverages this feature when it needs to compress and decompress data (strings, structured in-memory content, or files).</p>
<pre><code class="lang-brew">brew install zlib openssl readline
CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib"
</code></pre>
<h3 id="heading-step-3">Step 3:</h3>
<p>Once the installation is done, we'll export and setup paths for the environment variables for zlib. Run the following in the command line:</p>
<pre><code>$ <span class="hljs-keyword">export</span> LDFLAGS=$LDFLAGS:-L/usr/local/opt/zlib/lib
$ <span class="hljs-keyword">export</span> CPPFLAGS=$CPPFLAGS:-I/usr/local/opt/zlib/include
$ <span class="hljs-keyword">export</span> PKG_CONFIG_PATH=$PKG_CONFIG_PATH:~<span class="hljs-regexp">/usr/</span>local/opt/zlib/lib/pkgconfig
</code></pre><p>To view if the paths were correctly set, run this command:</p>
<pre><code>$ echo $LDFLAGS $CPPFLAGS $PKG_CONFIG_PATH
</code></pre><h3 id="heading-step-4">Step 4:</h3>
<p>Back in our terminal where we pulled the repository, we need to run the bundled installer with the code below:</p>
<pre><code>$ ./aws-elastic-beanstalk-cli-setup/scripts/bundled_installer
</code></pre><p>Once the process is complete you'll see an output that looks something like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/Screenshot-2021-01-09-at-14.33.22.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/Screenshot-2021-01-09-at-14.33.34.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-step-5">Step 5:</h3>
<p>To complete the installation process, we need to add <code>eb</code> and <code>python</code> to our environment path as well. We can do this by running this code in the terminal:</p>
<pre><code>$ echo <span class="hljs-string">'export PATH="/Users/user/.ebcli-virtual-env/executables:$PATH"'</span> &gt;&gt; ~<span class="hljs-regexp">/.bash_profile &amp;&amp; source ~/</span>.bash_profile
$ echo <span class="hljs-string">'export PATH=/Users/user/.pyenv/versions/3.7.2/bin:$PATH'</span> &gt;&gt; <span class="hljs-regexp">/Users/u</span>ser/.bash_profile &amp;&amp; source /Users/user/.bash_profile
</code></pre><p>Once we are done adding the paths, we can now try to initialize an Elastic Beanstalk and see if we get a list of selected regions. Run this in the terminal:</p>
<pre><code>$ eb init
</code></pre><p>And you should see the following:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/Screenshot-2021-01-09-at-14.44.03.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Voilà! We have a list of regions that we can choose from and we can add our credentials from an S3 bucket on AWS. We can also run other EB commands such as <code>eb create</code>, <code>eb deploy</code>, and a lot more.</p>
<h3 id="heading-references">References</h3>
<ul>
<li><a target="_blank" href="https://docs.amazonaws.cn/en_us/elasticbeanstalk/latest/dg/awseb-dg.pdf">AWS Elastic Beanstalk Developer Guide</a></li>
<li><a target="_blank" href="https://www.zlib.net/">Compression with zlib</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Facades in Laravel ]]>
                </title>
                <description>
                    <![CDATA[ Facades are one of the key things you should understand when learning Laravel. It took me a considerable amount of time to figure out how facades work, and I'm writing this to help anyone who is having trouble wrapping their heads around the concept.... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-facades-in-laravel/</link>
                <guid isPermaLink="false">66ba2fc3f1ac6be9964fe7a5</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Tue, 08 Dec 2020 19:32:33 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c95ff740569d1a4ca0f32.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Facades are one of the key things you should understand when learning Laravel.</p>
<p>It took me a considerable amount of time to figure out how facades work, and I'm writing this to help anyone who is having trouble wrapping their heads around the concept.</p>
<p>In this article we'll cover what facades are, how they're used in Laravel, how you can build your own simple facade, and more.</p>
<h2 id="heading-what-is-a-facade-and-what-is-a-wrapper">What is a facade? And what is a wrapper?</h2>
<p>A facade in Laravel is a wrapper around a non-static function that turns it into a static function.</p>
<p>The word "wrapper" can also be used when describing design patterns. Wrapping an object to provide a simplified interface to it is often described as the "facade" pattern. </p>
<p>So in short, the <a target="_blank" href="https://en.wikipedia.org/wiki/Wrapper_function">wrapper</a> is the facade.</p>
<p>Before diving deeper into facades, it's important to understand what static and non-static functions are in PHP.</p>
<h3 id="heading-static-methods">Static Methods</h3>
<p>In Static methods we're not required to create an instance of a class to reference it. Static methods use double colons (::) when accessing properties or methods of a class:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Calc</span> </span>{
    <span class="hljs-keyword">const</span> GOLDEN_RATIO = <span class="hljs-string">'1.618'</span>;
}

<span class="hljs-keyword">echo</span> Calc::GOLDEN_RATIO;  <span class="hljs-comment">//1.618</span>
</code></pre>
<p>Reserved keywords like <code>self</code> , <code>static</code> and <code>parents</code> is used to reference properties or methods within a class:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">backend</span> </span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> language = <span class="hljs-string">"php"</span>;
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">language</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">echo</span> <span class="hljs-built_in">self</span>::language;
      }
}

backend::language();  <span class="hljs-comment">//php</span>
</code></pre>
<h3 id="heading-non-static-methods">Non-static Methods</h3>
<p>Non-static methods require that a given class be instantiated. In other words, they require an instance of the class to execute:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">backend</span></span>{

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">language</span>(<span class="hljs-params">$name</span>)</span>{

        <span class="hljs-keyword">echo</span> $name;
    }

}


$test = <span class="hljs-keyword">new</span> backend; <span class="hljs-comment">//creating an instance of the class</span>

$test-&gt;language(<span class="hljs-string">'php'</span>); <span class="hljs-comment">//php</span>
</code></pre>
<p>Now that we've gone over static and non-static methods, we can dive deeper into facades in Laravel.</p>
<h2 id="heading-laravel-facades">Laravel facades</h2>
<p>In the <code>vendors &gt; laravel  &gt; framework &gt; src &gt; illuminate &gt; support &gt; Facades</code> directory, there's a list of files which are the various facades that ship with Laravel by default.</p>
<p>Here's a screenshot of what the directory structure actually looks like in our editor:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/11/Screenshot-2020-11-26-at-01.06.09.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Let's use the working code from <code>Log.php</code> to examine facades in more detail – the same explanation should apply to all facades in any Laravel application.</p>
<h3 id="heading-laravels-log-facade">Laravel's Log facade</h3>
<p>Here's the code for Laravel's <code>Log</code> facade:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Log</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Facade</span>
</span>{
    <span class="hljs-comment">/**
     * Get the registered name of the component.
     *
     * <span class="hljs-doctag">@return</span> string
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'log'</span>;
    }
}
</code></pre>
<p><code>Log</code> is a class that extends the base facade which is from the namespace above.</p>
<p>Within the <code>Log</code> class we have a protected access modifier, <code>getFacadeAccessor</code>, and what that method does is it just returns <code>log</code>. </p>
<p>The name of this facade, <code>log</code>, is being returned so we can access the named facade anywhere within the Laravel application without initializing it. So we can do something like <code>Log::info('hello there');</code> anywhere really easily.</p>
<p>As you can see, facades make code easier to read, more organized, and make testing 10 times easier.</p>
<p>Since learning about <code>Log</code> from one of my co-workers, it's been my favorite debugging tool.</p>
<h2 id="heading-how-to-create-a-facade-in-laravel">How to create a facade in Laravel</h2>
<p>In this section we'll implement our own facade. The main objective here is to help learners understand how Laravel facades work.</p>
<p>We'll do this by creating a StudentFacade which will extend properties from a base Facade that returns a name property after it has been resolved. This name property will be of type string and it will be returned each time we instantiate the class as shown below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/Screenshot-2020-12-05-at-21.13.39.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Curious how we will achieve this? Follow along as I'll be walking you through the steps.</p>
<p>We won't be creating our facade using the normal Laravel convention where we have a <code>.php file</code> in <code>app &gt; facade</code> and then another in the <code>providers</code> before we end up registering it in the <code>config &gt; app</code>. </p>
<p>Instead, we will make do with the <code>web.php</code> inside the <code>routes</code> for this illustration since we're just trying to see how facades work under the hood in a typical Laravel application.</p>
<p>First, let's start with this in <code>web.php</code>:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span> 
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span></span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">students</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'Sean'</span>;
    }
}

 app()-&gt;bind(<span class="hljs-string">'student'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
     <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Student;   
 });
</code></pre>
<p>We've created a class <code>Student</code>, and inside it we have a non-static <code>students</code> method that returns an array of students.</p>
<p>Then we call the <em>bind</em> method to make it always instantiate <code>new Student</code> so we don't need to do this manually anymore.</p>
<p>Next, let's create a base <code>Facade</code> class still within the same <code>web.php</code>:</p>
<pre><code class="lang-php"> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Facade</span></span>{
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__callStatic</span>(<span class="hljs-params">$name, $args</span>)</span>{
        <span class="hljs-keyword">return</span> app()-&gt;make(<span class="hljs-built_in">static</span>::getFacadeAccessor())-&gt;$name();
    }

    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-comment">//override take place </span>
    }
}
</code></pre>
<p>Any facade we might create later will be extending the properties of this base facade.</p>
<p>Within the <code>Facade</code> class we have a <code>__callStatic</code> <a target="_blank" href="https://www.php.net/manual/en/language.oop5.magic.php">magic method</a> that helps us resolve the <code>static::getFacadeAccessor()</code> from the container with <code>app()-&gt;make()</code>. And with those we're able to access the <code>$name</code> property.</p>
<pre><code class="lang-php"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StudentFacade</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Facade</span> </span>{
    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'student'</span>;
    }
}
</code></pre>
<p>Here, <code>StudentFacade</code> inherits the properties of the base facade. Then we override <code>getFacadeAccessor()</code> and set the return value to be whatever we have each time we instantiate in the bind above <code>student</code>.</p>
<pre><code class="lang-php">StudentFacade::students(); <span class="hljs-comment">//output "Sean"</span>
</code></pre>
<p>When we try to call the facade which we created it returns "Sean" as expected. Now in the final step we have to put all these steps together:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span></span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">students</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'Sean'</span>;
    }
}

 app()-&gt;bind(<span class="hljs-string">'student'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Student;   
 }); 


 <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Facade</span></span>{
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__callStatic</span>(<span class="hljs-params">$name, $args</span>)</span>{
        <span class="hljs-keyword">return</span> app()-&gt;make(<span class="hljs-built_in">static</span>::getFacadeAccessor())-&gt;$name();
    }

    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-comment">//override take place </span>
    }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StudentFacade</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Facade</span> </span>{
    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'student'</span>;
    }
}

<span class="hljs-comment">//log or die it to the output</span>
dd(StudentFacade::students());
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/Screenshot-2020-12-05-at-21.13.39-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I hope that by the end of this lesson you have been able to broaden your knowledge about facades work. If you have questions or wish to continue the conversation feel free to tweet at me.</p>
<h3 id="heading-references">References</h3>
<p><a target="_blank" href="https://www.youtube.com/watch?v=zD2VJhOdI5c">Laravel Beginner tutorial</a> - Bitfumes</p>
<p><a target="_blank" href="https://stackoverflow.com/questions/3293752/where-and-how-is-the-term-used-wrapper-in-programming-what-does-it-help-to-do">What is WRAPPER in programming, what does it help to do?</a> - Stackoverflow</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Launch Sublime Text on Windows from Git Bash ]]>
                </title>
                <description>
                    <![CDATA[ If you have been trying to figure out how to open the Sublime Text editor from your Git bash, then you're in luck. This article will guide you through the process with little or no stress.  It took me a while to figure out how it's done, but now ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-launch-sublime-text-from-your-terminal/</link>
                <guid isPermaLink="false">66ba2fb3ab41bfc0b9b131e7</guid>
                
                    <category>
                        <![CDATA[ Bash ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Git ]]>
                    </category>
                
                    <category>
                        <![CDATA[ terminal ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Tue, 08 Sep 2020 21:29:29 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c98cd740569d1a4ca1c23.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you have been trying to figure out how to open the Sublime Text editor from your Git bash, then you're in luck. This article will guide you through the process with little or no stress. </p>
<p>It took me a while to figure out how it's done, but now I can share that knowledge with you all in this write up. By the end you will be able to launch Sublime Text from bash.</p>
<h3 id="heading-prerequisites">Prerequisites:</h3>
<ul>
<li>Make sure you have <a target="_blank" href="https://www.sublimetext.com/3">Sublime text editor</a> set up</li>
<li>Make sure you have <a target="_blank" href="https://git-scm.com/downloads">Git</a> installed</li>
</ul>
<h2 id="heading-getting-started">Getting started</h2>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Sublime_Text#:~:text=Sublime%20Text%20is%20a%20shareware,maintained%20under%20free%2Dsoftware%20licenses.">Sublime text</a> is a source code editor that helps software developers code and edit text or markup. </p>
<p>It has amazing features such as syntax highlighting, indentation, plugins and packages. All these features help make it easier and more comfortable to work with and contribute to a wide variety of programming language code bases.</p>
<p>Once you've downloaded and installed Sublime, it will be located within the program files as shown below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/sublime-text.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p>What we want to do is create an alias for the sublime_text.exe found within the Sublime Text 3 folder. Then when we type the alias into Git bash it auto launches the text editor.</p>
<h2 id="heading-how-to-configure-git-bash-with-sublime-alias">How to Configure Git Bash with Sublime Alias</h2>
<p>To begin configuring Git bash, we first need to open the bash terminal. Then we can proceed to explore various Linux commands in order to complete the configuration process .</p>
<p>First, we need to create a .bashrc file using the <strong><a target="_blank" href="https://www.geeksforgeeks.org/touch-command-in-linux-with-examples/">touch command</a></strong>. It's important that the file be created within the <strong>C:\Users\username\</strong> directory – otherwise you will get a permission denied error. </p>
<p>I have created the bash file within the specified directory, so mine looks like <strong>C:\Users\larry.bashrc</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/touch-1.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Next we need to edit the <strong>.bashrc file</strong> to include the alias we'll need to launch Sublime text:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/vim.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p>When we click on enter we will see an interface that looks somewhat like what we have below. Then you need to press <code>i</code> to enter the insert mode.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/insert.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now you have access and can type into the prompt. So we can add our alias there now, like this:</p>
<pre><code>alias subl=<span class="hljs-string">'C:/Program\ Files/Sublime\ Text\ 3/sublime_text.exe'</span>
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2020/09/alias.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Once we've included that, we can press <code>esc</code> to exit insert mode and then <code>:wq</code> to save and exit. </p>
<p>Once we are done with that we can head back to our bash to check if our configuration worked by doing <code>subl</code> as shown below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/sublz.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Yes, it works! And you can see Sublime Text launch itself. </p>
<p>I also figured out that if you have a working directory you can force Sublime to open that directory. I will navigate into a code base now and show the difference in the next screenshot:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/vue--app.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p>From the screenshot above, Sublime doesn't just launch a blank workspace – it launches with all project folders associated with that project. That's because we added a wildcard to the command. </p>
<p>I hope with this hack you will be able to setup an alias for Sublime Text. I really appreciate the answers on this stack overflow <strong><a target="_blank" href="https://stackoverflow.com/a/43431197/9352741">thread</a></strong>. It helped me form the knowledge I was able to share in this article . </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Setup a Contact Page in Laravel With and Without Attachments ]]>
                </title>
                <description>
                    <![CDATA[ I recently struggled a bit when trying to set up a contact page in Laravel. So I figured that I should blog about my experience, as it might help someone who wants to do the same. Laravel is an open source PHP framework used to develop web applicatio... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-setup-a-contact-page-in-laravel/</link>
                <guid isPermaLink="false">66ba2fb66e35b2ef1a340070</guid>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Wed, 29 Jul 2020 16:26:30 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c997d740569d1a4ca2005.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>I recently struggled a bit when trying to set up a contact page in Laravel. So I figured that I should blog about my experience, as it might help someone who wants to do the same.</p>
<p>Laravel is an <a target="_blank" href="https://opensource.com/resources/what-open-source">open source</a> PHP framework used to develop web applications. It follows the model-view-controller architectural pattern.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ol>
<li><a target="_blank" href="https://getcomposer.org/download/">Install composer</a></li>
<li>Set up your local server (<a target="_blank" href="https://www.apachefriends.org/download.html">xampp</a>, <a target="_blank" href="https://www.wampserver.com/en/download-wampserver-64bits/">wamp</a>)</li>
<li>Make sure you have a code editor installed (<a target="_blank" href="https://www.sublimetext.com/3">sublime text</a>, <a target="_blank" href="https://code.visualstudio.com/download">vs code</a>, <a target="_blank" href="https://atom.io/">atom</a> etc)</li>
<li>Install <a target="_blank" href="https://git-scm.com/downloads">Git</a> (enables source control &amp; versioning)</li>
</ol>
<h2 id="heading-getting-started">Getting Started</h2>
<p>With Git installed you have access to Git bash. With bash open you can work with the terminal to run commands that lets you install and use Laravel and its packages easily. </p>
<h2 id="heading-install-laravel-via-composer">Install Laravel via composer</h2>
<p>Once you have satisfied all the above conditions, we will use the below command to set up the Laravel installer:</p>
<pre><code>composer <span class="hljs-built_in">global</span> <span class="hljs-built_in">require</span> laravel/installer
</code></pre><p>The above command lets us download the Laravel installer using composer that we installed earlier.</p>
<pre><code>laravel <span class="hljs-keyword">new</span> project_name
</code></pre><p>This installation process takes a while so just be patient. <strong>Note</strong> that the installation will be done in the directory you specify in your bash terminal or any terminal you choose to use.</p>
<h2 id="heading-generating-a-basic-authentication-scaffold">Generating a basic authentication scaffold</h2>
<p>Once we have a copy of the Laravel app installed we should generate a basic authentication scaffold.</p>
<pre><code>cd project_name

composer <span class="hljs-built_in">require</span> laravel/ui

php artisan ui vue --auth
</code></pre><p>The above command will install layout view, registration view, and login view, as well as routes for all user authentication.</p>
<h2 id="heading-setting-up-environment-variables-in-the-env-file">Setting up environment variables in the .env file</h2>
<p>Next we need to set up our environment variables and establish a connection to our database (<strong>in this article we'll use a shared dummy ip address</strong>).</p>
<pre><code>DB_CONNECTION=mysql
DB_HOST=<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>
DB_PORT=<span class="hljs-number">3306</span>
DB_DATABASE=your_database_name
DB_USERNAME=server_username
DB_PASSWORD=server_password


MAIL_DRIVER=smtp
MAIL_HOST=domain.com
MAIL_PORT=<span class="hljs-number">465</span>
MAIL_USERNAME=noreply@domain.com
MAIL_PASSWORD=domain_password
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=noreply@domain.com
MAIL_FROM_NAME=<span class="hljs-string">"${APP_NAME}"</span>
</code></pre><p>Now we're done setting up the database connection. In my case I work with Xampp where I have <code>DB_USERNAME=root</code> and <code>DB_PASSWORD=</code>. Also don't forget to start your local server as shown below. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/07/xampp.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>Image of xampp server</em></p>
<h2 id="heading-versioning-the-database-and-starting-the-development-server">Versioning the database and starting the development server</h2>
<p>Before you can run migrations in Laravel you need to establish a connection to your database. Since I have specified  <code>your_database_name</code> in the .env configuration above I can click "create" and phpMyAdmin will build an empty database.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/07/your_database_name.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>Adding a database name</em></p>
<p>In Git bash, navigate or cd into the <code>project_name</code> directory and run the below command:</p>
<pre><code>cd project_name

php artisan migrate
</code></pre><p> This will run all default Laravel migrations in our application as long as you have created a matching <code>DB_DATABASE</code> which we created above. </p>
<pre><code>php artisan serve
</code></pre><p>We can now start our development server: </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/07/php-artisan-serve.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>Starting development server</em></p>
<h2 id="heading-creating-a-contactbladephp-file">Creating a contact.blade.php file</h2>
<p>Set up a contact page in the <strong>resources &gt; views folder</strong> like this:</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.client.app'</span>)

@section(<span class="hljs-string">'content'</span>)

&lt;!-- contact section --&gt;
    &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">contact</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">xl</span>-7 <span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-8 <span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">section</span>-<span class="hljs-title">title</span>"&gt;
                        &lt;<span class="hljs-title">h2</span>&gt;<span class="hljs-title">Contact</span> <span class="hljs-title">Us</span>&lt;/<span class="hljs-title">h2</span>&gt;
                    &lt;/<span class="hljs-title">div</span>&gt;
                &lt;/<span class="hljs-title">div</span>&gt;
            &lt;/<span class="hljs-title">div</span>&gt;

            @<span class="hljs-title">if</span>(<span class="hljs-title">session</span>('<span class="hljs-title">status</span>'))
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">xl</span>-8 <span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-8 <span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">success</span> <span class="hljs-title">alert</span>-<span class="hljs-title">dismissible</span> <span class="hljs-title">fade</span> <span class="hljs-title">show</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"&gt;
                        &lt;<span class="hljs-title">strong</span>&gt;<span class="hljs-title">Success</span> ! &lt;/<span class="hljs-title">strong</span>&gt;  &amp;<span class="hljs-title">nbsp</span>; </span>{{ session(<span class="hljs-string">'status'</span>) }}
                        &lt;button type=<span class="hljs-string">"button"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">close</span>" <span class="hljs-title">data</span>-<span class="hljs-title">dismiss</span>="<span class="hljs-title">alert</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">label</span>="<span class="hljs-title">Close</span>"&gt;
                            &lt;<span class="hljs-title">span</span> <span class="hljs-title">aria</span>-<span class="hljs-title">hidden</span>="<span class="hljs-title">true</span>"&gt;&amp;<span class="hljs-title">times</span>;&lt;/<span class="hljs-title">span</span>&gt;
                        &lt;/<span class="hljs-title">button</span>&gt;
                    &lt;/<span class="hljs-title">div</span>&gt;
                &lt;/<span class="hljs-title">div</span>&gt;
            &lt;/<span class="hljs-title">div</span>&gt;
            @<span class="hljs-title">endif</span>
        &lt;/<span class="hljs-title">div</span>&gt;
    &lt;/<span class="hljs-title">div</span>&gt;
@<span class="hljs-title">endsection</span></span>
</code></pre>
<p>The above code snippet will extend a layouts file containing the header section. It also contains the section title "Contact Us" along with a message that's been returned and displayed to the User if and only if the mail message was successfully sent.  </p>
<p>The main focus here is on the form section that you can see in the next code snippet:</p>
<pre><code class="lang-php">&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">xl</span>-8 <span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-8"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">login</span>-<span class="hljs-title">form</span>"&gt;
            &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">POST</span>" <span class="hljs-title">action</span>="</span>{{ route(<span class="hljs-string">'addContact'</span>) }}<span class="hljs-string">" enctype="</span>multipart/form-data<span class="hljs-string">"&gt;
                @csrf
                &lt;div class="</span>row<span class="hljs-string">"&gt;

                    &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                        &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                            &lt;label for="</span>name<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Full Name') }}&lt;/label&gt;

                            &lt;input type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'fullname'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>fullname<span class="hljs-string">" value="</span>{{ <span class="hljs-keyword">isset</span>(Auth::user()-&gt;firstname) ? Auth::user()-&gt;firstname : <span class="hljs-string">''</span> }} {{ <span class="hljs-keyword">isset</span>(Auth::user()-&gt;lastname) ? Auth::user()-&gt;lastname : <span class="hljs-string">''</span> }}<span class="hljs-string">" required autocomplete="</span>Fullname<span class="hljs-string">" autofocus&gt;

                            @error('fullname')
                                &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                    &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                &lt;/span&gt;
                            @enderror
                        &lt;/div&gt;
                    &lt;/div&gt;

                    &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;

                        &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                            &lt;label for="</span>email<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Email Address') }}&lt;/label&gt;

                            &lt;input type="</span>email<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'email'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>email<span class="hljs-string">" value="</span>{{ <span class="hljs-keyword">isset</span>(Auth::user()-&gt;email) ? Auth::user()-&gt;email : <span class="hljs-string">''</span> }}<span class="hljs-string">" required autocomplete="</span>email<span class="hljs-string">" autofocus&gt;

                            @error('email')
                                &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                    &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                &lt;/span&gt;
                            @enderror
                        &lt;/div&gt;

                    &lt;/div&gt;

                    &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;

                        &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                            &lt;label for="</span>name<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Phone Number') }}&lt;/label&gt;

                            &lt;input type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'phone_number'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>phone_number<span class="hljs-string">" value="</span>{{ <span class="hljs-keyword">isset</span>(Auth::user()-&gt;phone_number) ? Auth::user()-&gt;phone_number : <span class="hljs-string">''</span> }}<span class="hljs-string">" required autocomplete="</span>phone_number<span class="hljs-string">" autofocus&gt;

                            @error('phone_number')
                                &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                    &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                &lt;/span&gt;
                            @enderror
                        &lt;/div&gt;
                    &lt;/div&gt;

                    &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;


                        &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                            &lt;label for="</span>name<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Subject') }}&lt;/label&gt;

                            &lt;input type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'subject'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>subject<span class="hljs-string">" required autofocus&gt;

                            @error('subject')
                                &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                    &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                &lt;/span&gt;
                            @enderror
                        &lt;/div&gt;
                    &lt;/div&gt;

                    &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                        &lt;div class="</span>form-group<span class="hljs-string">"&gt;

                            &lt;label for="</span>password<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Message') }}&lt;/label&gt;

                            &lt;textarea class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'message'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>message<span class="hljs-string">" required&gt;&lt;/textarea&gt;

                            @error('message')
                                &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                    &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                &lt;/span&gt;
                            @enderror
                        &lt;/div&gt;
                    &lt;/div&gt;

                    &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;

                        &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                            &lt;label for="</span>name<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Attach Screenshot') }}&lt;/label&gt;

                            &lt;input type="</span>file<span class="hljs-string">" accept="</span>image<span class="hljs-comment">/*" class="form-control <span class="hljs-doctag">@error</span>('screenshot') is-invalid <span class="hljs-doctag">@enderror</span>" name="screenshot" autofocus&gt;

                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class="form-group row mb-0"&gt;
                    &lt;div class="col-md-6 offset-md-4"&gt;
                        &lt;button type="submit" class="btn btn-primary"&gt;
                            {{ __('Send Message') }}
                        &lt;/button&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/form&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;</span>
</code></pre>
<p>The snippet above contains the various input fields that we will use in processing user information. The fields include FULLNAME, EMAIL ADDRESS, PHONE NUMBER , SUBJECT or PURPOSE , MESSAGE , IMAGE UPLOAD (if any) and finally a SEND MESSAGE button to process the submission of the form. </p>
<p>Next we will merge both code snippets together to make them lot more meaningful.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.client.app'</span>)
@section(<span class="hljs-string">'content'</span>)
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">contact</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">xl</span>-7 <span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-8 <span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">section</span>-<span class="hljs-title">title</span>"&gt;
                    &lt;<span class="hljs-title">h2</span>&gt;<span class="hljs-title">Contact</span> <span class="hljs-title">Us</span>&lt;/<span class="hljs-title">h2</span>&gt;
                &lt;/<span class="hljs-title">div</span>&gt;
            &lt;/<span class="hljs-title">div</span>&gt;
        &lt;/<span class="hljs-title">div</span>&gt;

        @<span class="hljs-title">if</span>(<span class="hljs-title">session</span>('<span class="hljs-title">status</span>'))
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">xl</span>-8 <span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-8 <span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">success</span> <span class="hljs-title">alert</span>-<span class="hljs-title">dismissible</span> <span class="hljs-title">fade</span> <span class="hljs-title">show</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"&gt;
                    &lt;<span class="hljs-title">strong</span>&gt;<span class="hljs-title">Success</span> ! &lt;/<span class="hljs-title">strong</span>&gt;  &amp;<span class="hljs-title">nbsp</span>; </span>{{ session(<span class="hljs-string">'status'</span>) }}
                    &lt;button type=<span class="hljs-string">"button"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">close</span>" <span class="hljs-title">data</span>-<span class="hljs-title">dismiss</span>="<span class="hljs-title">alert</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">label</span>="<span class="hljs-title">Close</span>"&gt;
                        &lt;<span class="hljs-title">span</span> <span class="hljs-title">aria</span>-<span class="hljs-title">hidden</span>="<span class="hljs-title">true</span>"&gt;&amp;<span class="hljs-title">times</span>;&lt;/<span class="hljs-title">span</span>&gt;
                    &lt;/<span class="hljs-title">button</span>&gt;
                &lt;/<span class="hljs-title">div</span>&gt;
            &lt;/<span class="hljs-title">div</span>&gt;
        &lt;/<span class="hljs-title">div</span>&gt;
        @<span class="hljs-title">endif</span>
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">xl</span>-8 <span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-8"&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">login</span>-<span class="hljs-title">form</span>"&gt;
                        &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">POST</span>" <span class="hljs-title">action</span>="</span>{{ route(<span class="hljs-string">'addContact'</span>) }}<span class="hljs-string">" enctype="</span>multipart/form-data<span class="hljs-string">"&gt;
                            @csrf
                            &lt;div class="</span>row<span class="hljs-string">"&gt;

                                &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                    &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                                        &lt;label for="</span>name<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Full Name') }}&lt;/label&gt;

                                        &lt;input type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'fullname'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>fullname<span class="hljs-string">" value="</span>{{ <span class="hljs-keyword">isset</span>(Auth::user()-&gt;firstname) ? Auth::user()-&gt;firstname : <span class="hljs-string">''</span> }} {{ <span class="hljs-keyword">isset</span>(Auth::user()-&gt;lastname) ? Auth::user()-&gt;lastname : <span class="hljs-string">''</span> }}<span class="hljs-string">" required autocomplete="</span>Fullname<span class="hljs-string">" autofocus&gt;

                                        @error('fullname')
                                            &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                                &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                            &lt;/span&gt;
                                        @enderror
                                    &lt;/div&gt;
                                &lt;/div&gt;

                                &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;

                                    &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                                        &lt;label for="</span>email<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Email Address') }}&lt;/label&gt;

                                        &lt;input type="</span>email<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'email'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>email<span class="hljs-string">" value="</span>{{ <span class="hljs-keyword">isset</span>(Auth::user()-&gt;email) ? Auth::user()-&gt;email : <span class="hljs-string">''</span> }}<span class="hljs-string">" required autocomplete="</span>email<span class="hljs-string">" autofocus&gt;

                                        @error('email')
                                            &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                                &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                            &lt;/span&gt;
                                        @enderror
                                    &lt;/div&gt;

                                &lt;/div&gt;

                                &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;

                                    &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                                        &lt;label for="</span>name<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Phone Number') }}&lt;/label&gt;

                                        &lt;input type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'phone_number'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>phone_number<span class="hljs-string">" value="</span>{{ <span class="hljs-keyword">isset</span>(Auth::user()-&gt;phone_number) ? Auth::user()-&gt;phone_number : <span class="hljs-string">''</span> }}<span class="hljs-string">" required autocomplete="</span>phone_number<span class="hljs-string">" autofocus&gt;

                                        @error('phone_number')
                                            &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                                &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                            &lt;/span&gt;
                                        @enderror
                                    &lt;/div&gt;
                                &lt;/div&gt;

                                &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;


                                    &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                                        &lt;label for="</span>name<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Subject') }}&lt;/label&gt;

                                        &lt;input type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'subject'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>subject<span class="hljs-string">" required autofocus&gt;

                                        @error('subject')
                                            &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                                &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                            &lt;/span&gt;
                                        @enderror
                                    &lt;/div&gt;
                                &lt;/div&gt;

                                &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                    &lt;div class="</span>form-group<span class="hljs-string">"&gt;

                                        &lt;label for="</span>password<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Message') }}&lt;/label&gt;

                                        &lt;textarea class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'message'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>message<span class="hljs-string">" required&gt;&lt;/textarea&gt;

                                        @error('message')
                                            &lt;span class="</span>invalid-feedback<span class="hljs-string">" role="</span>alert<span class="hljs-string">"&gt;
                                                &lt;strong&gt;{{ <span class="hljs-subst">$message</span> }}&lt;/strong&gt;
                                            &lt;/span&gt;
                                        @enderror
                                    &lt;/div&gt;
                                &lt;/div&gt;

                                &lt;div class="</span>col<span class="hljs-number">-6</span><span class="hljs-string">"&gt;

                                    &lt;div class="</span>form-group<span class="hljs-string">"&gt;
                                        &lt;label for="</span>name<span class="hljs-string">" class="</span>col-form-label text-md-right<span class="hljs-string">"&gt;{{ __('Attach Screenshot') }}&lt;/label&gt;

                                        &lt;input type="</span>file<span class="hljs-string">" accept="</span>image<span class="hljs-comment">/*" class="form-control <span class="hljs-doctag">@error</span>('screenshot') is-invalid <span class="hljs-doctag">@enderror</span>" name="screenshot" autofocus&gt;

                                    &lt;/div&gt;
                                &lt;/div&gt;
                            &lt;/div&gt;

                            &lt;div class="form-group row mb-0"&gt;
                                &lt;div class="col-md-6 offset-md-4"&gt;
                                    &lt;button type="submit" class="btn btn-primary"&gt;
                                        {{ __('Send Message') }}
                                    &lt;/button&gt;
                                &lt;/div&gt;
                            &lt;/div&gt;
                        &lt;/form&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
<span class="hljs-doctag">@endsection</span></span>
</code></pre>
<p>The image below is a simple layout of what the contact page looks like right now. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/07/Contact-us-2.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>Contact us page</em></p>
<h2 id="heading-add-routes-to-enable-get-amp-post-requests">Add routes to enable GET &amp; POST requests</h2>
<p>First, we'll set up the routes in <strong>routes &gt; web.php</strong> to render the contact page via a <strong>GET</strong> request and send mails via the <strong>POST</strong> request (which has been specified in the form attribute above).</p>
<pre><code class="lang-php">Route::get(<span class="hljs-string">'/contact'</span>, <span class="hljs-string">'HomeController@index'</span>)-&gt;name(<span class="hljs-string">'contact'</span>);

Route::post(<span class="hljs-string">'/contact'</span>, <span class="hljs-string">'HomeController@send_mail'</span>)-&gt;name(<span class="hljs-string">'addContact'</span>);
</code></pre>
<h2 id="heading-adding-logic-within-the-homecontroller">Adding logic within the HomeController</h2>
<p>In <strong>app &gt; Http &gt; Controllers,</strong> Laravel scaffold generated a HomeController. </p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</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">HomeController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">'template.client.contact'</span>); <span class="hljs-comment">//renders the contact page</span>
    }

}
</code></pre>
<p>The Controller file is where the logic of the application resides. Laravel Scaffold already generated the default HomeController. So we will make do with that and create a function named <code>index</code>. We will use it to render the contact us page each time the user visits the route or URL in the application.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</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">Mail</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Mail</span>\<span class="hljs-title">ContactFormMail</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HomeController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">send_mail</span>(<span class="hljs-params">Request $request</span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;validate($request, [
            <span class="hljs-string">'fullname'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span> ], 
            <span class="hljs-string">'email'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'email'</span>, <span class="hljs-string">'max:255'</span> ],
            <span class="hljs-string">'phone_number'</span> =&gt; [<span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>],
            <span class="hljs-string">'subject'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>],
            <span class="hljs-string">'message'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>]
        ]);

        $contact = [
            <span class="hljs-string">'fullname'</span> =&gt; $request[<span class="hljs-string">'fullname'</span>], 
            <span class="hljs-string">'email'</span> =&gt; $request[<span class="hljs-string">'email'</span>],
            <span class="hljs-string">'phone_number'</span> =&gt; $request[<span class="hljs-string">'phone_number'</span>],
            <span class="hljs-string">'subject'</span> =&gt; $request[<span class="hljs-string">'subject'</span>],
            <span class="hljs-string">'message'</span> =&gt; $request[<span class="hljs-string">'message'</span>],
            <span class="hljs-string">'screenshot'</span> =&gt; $request-&gt;file(<span class="hljs-string">'screenshot'</span>)-&gt;store(<span class="hljs-string">'contact'</span>, <span class="hljs-string">'public'</span>)
        ];


        Mail::to(<span class="hljs-string">'receipent@domain.com'</span>)-&gt;send(<span class="hljs-keyword">new</span> ContactFormMail($contact));

        <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'contact'</span>)-&gt;with(<span class="hljs-string">'status'</span>, <span class="hljs-string">'Your Mail has been received'</span>);
    }
}
</code></pre>
<p>In the same HomeController, we need to create another function named <code>send_mail</code> . The function will validate all user input and check to make sure fields are not left empty and the right data is parsed. </p>
<p>Next create a variable called <code>$create</code> to store the array values of all user data including image uploads. </p>
<p>Laravel ships with a filesystem that lets us work with images easily. The <code>Mail::to(....)</code>and <code>send</code> ship with Illuminate\Support\Facade which I included at the top of the snippet. I have also included a Mailable, which I will explain soon. </p>
<p>We now need to alert users when the message has been dispatched and redirect them. </p>
<p>Bringing the code snippets together now will make the HomeController look somewhat like this:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</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-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">Mail</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Mail</span>\<span class="hljs-title">ContactFormMail</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HomeController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">'template.client.contact'</span>); <span class="hljs-comment">//renders the contact page</span>
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">send_mail</span>(<span class="hljs-params">Request $request</span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;validate($request, [
            <span class="hljs-string">'fullname'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span> ], 
            <span class="hljs-string">'email'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'email'</span>, <span class="hljs-string">'max:255'</span> ],
            <span class="hljs-string">'phone_number'</span> =&gt; [<span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>],
            <span class="hljs-string">'subject'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>],
            <span class="hljs-string">'message'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>]
        ]);

        $contact = [
            <span class="hljs-string">'fullname'</span> =&gt; $request[<span class="hljs-string">'fullname'</span>], 
            <span class="hljs-string">'email'</span> =&gt; $request[<span class="hljs-string">'email'</span>],
            <span class="hljs-string">'phone_number'</span> =&gt; $request[<span class="hljs-string">'phone_number'</span>],
            <span class="hljs-string">'subject'</span> =&gt; $request[<span class="hljs-string">'subject'</span>],
            <span class="hljs-string">'message'</span> =&gt; $request[<span class="hljs-string">'message'</span>],
            <span class="hljs-string">'screenshot'</span> =&gt; $request-&gt;file(<span class="hljs-string">'screenshot'</span>)-&gt;store(<span class="hljs-string">'contact'</span>, <span class="hljs-string">'public'</span>)
        ];


        Mail::to(<span class="hljs-string">'receipent@domain.com'</span>)-&gt;send(<span class="hljs-keyword">new</span> ContactFormMail($contact));

        <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'contact'</span>)-&gt;with(<span class="hljs-string">'status'</span>, <span class="hljs-string">' Your Mail has been received'</span>);
    }
}
</code></pre>
<p>Having merged both of the above functions, we are done with the logic for the HomeController. Now let's proceed to the next step. </p>
<h2 id="heading-generating-laravel-mailablehttpslaravelcomdocs7xmail">Generating <a target="_blank" href="https://laravel.com/docs/7.x/mail">Laravel Mailable</a></h2>
<p>Each mail sent within the Laravel application is represented as a "mailable" just in case you're wondering about the name. Let's create a markdown mailable for contact information that we want to process:</p>
<pre><code class="lang-php">php artisan make:mail ContactFormMail --markdown=template.client.contactform
</code></pre>
<p>The command above will generate a markdown file in the <strong>resources &gt; views &gt; template &gt; client</strong> directory and also create a mailable file in <strong>app &gt; Mail &gt; ContactFormMail.php</strong>.</p>
<p>In ContactFormMail.php we have the following code snippet that lets us send mails <strong>without</strong> an attachment:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Mail</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Bus</span>\<span class="hljs-title">Queueable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Contracts</span>\<span class="hljs-title">Queue</span>\<span class="hljs-title">ShouldQueue</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Mail</span>\<span class="hljs-title">Mailable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Queue</span>\<span class="hljs-title">SerializesModels</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ContactFormMail</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Mailable</span>
</span>{
    <span class="hljs-keyword">use</span> <span class="hljs-title">Queueable</span>, <span class="hljs-title">SerializesModels</span>;

    <span class="hljs-comment">/**
    * Create a new message instance.
    *
    * <span class="hljs-doctag">@return</span> void
    */</span>

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params">$data</span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;user = $data;
    }

    <span class="hljs-comment">/**
     * Build the message.
     *
     * <span class="hljs-doctag">@return</span> $this
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">build</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;from(<span class="hljs-string">'noreply@domain.com'</span>)
                -&gt;markdown(<span class="hljs-string">'template.client.contactform'</span>)
                -&gt;with([
                        <span class="hljs-string">'subject'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'subject'</span>],
                        <span class="hljs-string">'message'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'message'</span>],
                        <span class="hljs-string">'email'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'email'</span>],
                        <span class="hljs-string">'phone_number'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'phone_number'</span>],
                        <span class="hljs-string">'fullname'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'fullname'</span>],
                    ]);
    }
}
</code></pre>
<p>Let's break this code down a bit.</p>
<p>In the <code>**_construct**</code> method I'm parsing all user data as a parameter and reassigning it. In the <code>**build**</code> method, all of the mailable class configuration is done.</p>
<p>The <code>**from**</code> <strong>Method</strong> specifies the mail sender, that is who the mail is coming from (in my case <strong>noreply@domain.com</strong>).</p>
<p>The <code>**with**</code>  <strong>Method</strong> lets you choose to customize how mails will be rendered to the markdown which was generated. In this article we will assign all the fields to key and value pairs within the array so that within the markdown we can access each value with its own unique key.</p>
<p>The <code>**markdown**</code> <strong>Method</strong> accepts the name the of markdown template to be rendered with an optional data parameter (if we weren't making use of the <code>**with**</code> method).</p>
<p>And lastly, the <code>**to**</code> <strong>Method</strong> specifies the recipient of the mail. In the HomeController above, change 'receipent@domain.com' to the actual recipient's address.</p>
<h2 id="heading-add-data-to-the-markdown-file">Add Data to the Markdown File</h2>
<p>Now we need to configure the markdown file in the <strong>resources &gt; views &gt; template &gt; client</strong> directory. Since we have key value pairs in place already, it's easier to reference with keys in the markdown file as shown below:</p>
<pre><code class="lang-php">@component(<span class="hljs-string">'mail::message'</span>)
<span class="hljs-comment"># {{$subject}}</span>

<span class="hljs-comment">## {{$message}}</span>

Feel free to contact me via {{$phone}} <span class="hljs-keyword">or</span> {{$email}}

Thanks,&lt;br&gt;
{{$fullname}}

{{ config(<span class="hljs-string">'app.name'</span>) }}
@endcomponent
</code></pre>
<p>At this point we're almost done ???. Kudos for following along with the process this far.  You have now learned how to send an email without attachment. Now let's look at how to do it with an attachment.</p>
<h2 id="heading-sending-mails-with-an-attachment">Sending Mails with an Attachment</h2>
<p>Laravel already ships with a powerful <a target="_blank" href="https://laravel.com/docs/7.x/filesystem">filesystem</a>, so sending mails with an attachment isn't too difficult. We will leverage this feature and create storage for users where we will store their attached files within the application.  </p>
<pre><code class="lang-php">php artisan storage:link
</code></pre>
<p><strong>NOTE</strong> : In HomeController above I already specified a storage directory for the uploads. You should do same by creating a folder (called <strong>contact</strong>) in <strong>storage &gt; app &gt; public &gt; contact</strong> .</p>
<p>Also in the <strong>config &gt; filesystems.php</strong> check and make sure the default filesystem disk is set to <code>return ['default' =&gt; 'public']</code>.</p>
<p>Now the <strong><a target="_blank" href="https://www.freecodecamp.org/news/p/7a16e74f-8e36-4e21-9344-feba5c03da08/ContactFormMail.php">Cont</a>actFormMail.php</strong> looks like this. We are now able to use the   <code>attachFromStorage</code> method which makes reference to the filepath.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Mail</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Bus</span>\<span class="hljs-title">Queueable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Contracts</span>\<span class="hljs-title">Queue</span>\<span class="hljs-title">ShouldQueue</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Mail</span>\<span class="hljs-title">Mailable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Queue</span>\<span class="hljs-title">SerializesModels</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ContactFormMail</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Mailable</span>
</span>{
    <span class="hljs-keyword">use</span> <span class="hljs-title">Queueable</span>, <span class="hljs-title">SerializesModels</span>;

    <span class="hljs-comment">/**
    * Create a new message instance.
    *
    * <span class="hljs-doctag">@return</span> void
    */</span>
    <span class="hljs-keyword">public</span> $user;

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params">$data</span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;user = $data;
    }

    <span class="hljs-comment">/**
     * Build the message.
     *
     * <span class="hljs-doctag">@return</span> $this
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">build</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;from(<span class="hljs-string">'noreply@domain.com'</span>)
                -&gt;markdown(<span class="hljs-string">'template.client.contactform'</span>)
                -&gt;attachFromStorage(<span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'screenshot'</span>])
                -&gt;with([
                        <span class="hljs-string">'subject'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'subject'</span>],
                        <span class="hljs-string">'message'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'message'</span>],
                        <span class="hljs-string">'email'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'email'</span>],
                        <span class="hljs-string">'phone_number'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'phone_number'</span>],
                        <span class="hljs-string">'fullname'</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;user[<span class="hljs-string">'fullname'</span>]
                    ]);
    }
}
</code></pre>
<p>The only addition here will be <strong>attachFromStorage.</strong> It is used to process the attached files (either image or pdf) during the entire mailing process. </p>
<p>In the markdown file that we earlier used, we can slightly rework it to look like what's shown below:</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"row"</span>&gt;
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-dark"</span>&gt;</span>{{$subject}}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>

    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>{{$message}}<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span></span> 

    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>You can reach me via mail or telephone : {{$email}} or {{$phone_number}}<span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>
    Thanks
    <span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span></span>
&lt;/div&gt;
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2020/07/Screenshot_20200724-180046.png" alt="Image" width="600" height="400" loading="lazy">
<em>Screenshot of successful mail message</em></p>
<p>Yaaay we can now do a happy dance because we're finally done ?????</p>
<p><div class="embed-wrapper"><iframe src="https://giphy.com/embed/zQLjk9d31jlMQ" width="480" height="262" class="giphy-embed" title="Embedded content" loading="lazy"></iframe></div></p><p><a href="https://giphy.com/gifs/dancing-dance-woo-zQLjk9d31jlMQ">via GIPHY</a></p><p></p>
<p>Now that you've made it through the entire article, you should be able to implement a similar emailing feature in your Laravel applications. </p>
<p>To learn more you can check out the official <a target="_blank" href="https://laravel.com/docs/">Laravel documentation here.</a>  </p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
