<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kingsconsult</title>
    <description>The latest articles on Forem by Kingsconsult (@kingsconsult).</description>
    <link>https://forem.com/kingsconsult</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F207008%2F6be60c51-19c9-46cf-bfd1-4370aec78d12.jpg</url>
      <title>Forem: Kingsconsult</title>
      <link>https://forem.com/kingsconsult</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kingsconsult"/>
    <language>en</language>
    <item>
      <title>Laravel Credit Card Validation</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Sat, 09 Jan 2021 10:15:12 +0000</pubDate>
      <link>https://forem.com/kingsconsult/laravel-credit-card-validation-58ig</link>
      <guid>https://forem.com/kingsconsult/laravel-credit-card-validation-58ig</guid>
      <description>&lt;p&gt;Hello, Today we are going to be looking at validating credit card, adding a credit card to our app needs some level of validation before it will be store in the database.&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Install the package required&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We are going to be using a package &lt;strong&gt;Laravel Validator Rules - Credit Card&lt;/strong&gt;, so we need to install it&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer require laravel-validation-rules/credit-card&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610186481%2Flaravel%2520form%2520validation%2F1_s3zekv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610186481%2Flaravel%2520form%2520validation%2F1_s3zekv.png" alt="install LVR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Create the Form Request&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For a comprehensive explanation of this step, check out this material &lt;a href="https://dev.to/kingsconsult/laravel-form-validation-5dla/edit"&gt;Laravel Form Validation&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan make:request CardVerificationRequest&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Write the Form Request Rules and Error Message&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Open the file that is created in &lt;strong&gt;app/Http/Requests/&lt;/strong&gt;, &lt;strong&gt;CardVerificationRequest.php&lt;/strong&gt; and edit to this&lt;br&gt;
&lt;/p&gt;

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

namespace App\Http\Requests;

use LVR\CreditCard\CardCvc;
use LVR\CreditCard\CardNumber;
use LVR\CreditCard\CardExpirationYear;
use LVR\CreditCard\CardExpirationMonth;
use Illuminate\Foundation\Http\FormRequest;

class CardVerificationRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'card_number' =&amp;gt; ['required', 'unique:cards,cardNo', new CardNumber],
            'expiration_year' =&amp;gt; ['required', new CardExpirationYear($this-&amp;gt;get('expiration_month'))],
            'expiration_month' =&amp;gt; ['required', new CardExpirationMonth($this-&amp;gt;get('expiration_year'))],
            'cvc' =&amp;gt; ['required', new CardCvc($this-&amp;gt;get('card_number'))]
        ];
    }

    public function messages()
    {
        return [
            'card_number.required' =&amp;gt; 'The card number is compulsory'
        ];
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Type-hint the CardVerificationRequest in our Controller&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to the controller method, where you want to use the validation and use my code as a guide&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    /**
     * Store a newly created resource in storage.
     *
     * @param  \App\Http\Requests\CardVerificationRequest  $request
     * @return \Illuminate\Http\Response
     */
    public function store(CardVerificationRequest $request)
    {

        $validatedData = $request-&amp;gt;validated();

        $newCard = new Card;

        $newCard-&amp;gt;cardNo = $validatedData["card_number"];
        $newCard-&amp;gt;cardExpiringMonth = $validatedData["expiration_month"];
        $newCard-&amp;gt;cardExpiringYear = $validatedData["expiration_year"];
        $newCard-&amp;gt;cardCVV = $validatedData["cvc"];

        $newCard-&amp;gt;save();

        return response()-&amp;gt;json([
            "status" =&amp;gt; "success",
            "message" =&amp;gt; "Card saved successfully.",
            "data" =&amp;gt; $newCard
        ], StatusCodes::SUCCESS);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Testing&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Running the app with fields that violates the rules&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610186482%2Flaravel%2520form%2520validation%2F2_vn5eqr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610186482%2Flaravel%2520form%2520validation%2F2_vn5eqr.png" alt="error"&gt;&lt;/a&gt;&lt;br&gt;
When the fields are correct&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610186481%2Flaravel%2520form%2520validation%2F3_db0dmk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610186481%2Flaravel%2520form%2520validation%2F3_db0dmk.png" alt="successful"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me for more of my articles, you can leave comments, suggestions, and reactions.&lt;br&gt;
I am open to any vacancy as a PHP (Laravel) backend engineer, I am also available for any job. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for your time&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>webdev</category>
      <category>security</category>
    </item>
    <item>
      <title>Laravel Form Validation</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Sat, 02 Jan 2021 22:59:26 +0000</pubDate>
      <link>https://forem.com/kingsconsult/laravel-form-validation-5dla</link>
      <guid>https://forem.com/kingsconsult/laravel-form-validation-5dla</guid>
      <description>&lt;p&gt;Hello, Happy New Year, Hope you are enjoying the yuletide period? Today, I am going to write on Form Validation in Laravel. When we are building an application that requires a user filling a form and the application storing the data in the database, there is always a need to validate, if not, a user can decide or mistakenly enter the wrong data in a field and summit and the application will process it, but if there are some validation rules before the storing method will process it, it will return an error to check the form input.&lt;br&gt;
Laravel has some default validation rules out of the box, but there are some instances we will want to define our own set of rules. There might be a complex scenario so you will need to create a &lt;strong&gt;form request&lt;/strong&gt;, also in programming, the &lt;strong&gt;SRP&lt;/strong&gt; of &lt;strong&gt;SOLID&lt;/strong&gt; principle states that a class should perform just one task, so our store method of controller needs to only handle storing of data and not validation.&lt;br&gt;
Let's dive in, you will understand it better.&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Create Form Request&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To create a form request, we are going to use an artisan command&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan make:request StoreProjectRequest&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A folder called &lt;strong&gt;Requests&lt;/strong&gt; will be created in &lt;strong&gt;app/Http/&lt;/strong&gt; directory with the &lt;strong&gt;StoreProjectRequest.php&lt;/strong&gt; file, open the file and let's write our validation rules.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610180362%2Flaravel%2520form%2520validation%2F1_d9dxtf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610180362%2Flaravel%2520form%2520validation%2F1_d9dxtf.png" alt="storeProjectRequest"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Write the Validation rules&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;app/Http/Requests/StoreProjectRequest.php&lt;/strong&gt;&lt;br&gt;
All the fields that we want to validate should be written in a key-value pair in the return of the rules methods&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public function rules()
    {
        return [
            'name' =&amp;gt; 'required|max:100',
            'introduction' =&amp;gt; 'required|max:255',
            'location' =&amp;gt; 'nullable',
            'cost' =&amp;gt; 'required|integer'
        ];
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Write the error messages&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is optional because Laravel has provided a set of error messages. However, we can decide to write our error messages for each error.&lt;br&gt;
Create a method called &lt;strong&gt;message()&lt;/strong&gt; and return an array of the error messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public function messages()
    {
        return [
            'name.required' =&amp;gt; 'You need to provide the name of the project',
            'name.max' =&amp;gt; 'The name of the project should not be greater than 100 characters',
            'introduction.required' =&amp;gt; 'Please provide the introduction of the project',
            'cost.integer' =&amp;gt; 'The cost of the project must be a number'
        ];
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, the StoreProjectRequest will now look like this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610181000%2Flaravel%2520form%2520validation%2F4_jssk9h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610181000%2Flaravel%2520form%2520validation%2F4_jssk9h.png" alt="StoreProjectRequest"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Type-hint the Request in the Controller&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now go to our controller, and the store method where we want to validate, then type-hint the &lt;strong&gt;StoreProjectRequest&lt;/strong&gt; replacing the usual &lt;strong&gt;Request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   public function store(StoreProjectRequest $request)
    {
        $request-&amp;gt;validated();

        Project::create($request-&amp;gt;all());

        return redirect()-&amp;gt;route('projects.index')
            -&amp;gt;with('success', 'Project created successfully.');
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can retrieved the validated request like this  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$validated = $request-&amp;gt;validated();&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So you can use it like this &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$projectName = $validated["name"];&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If there is an error, the errors will be stored in the error bag and send back to the view or store in the session.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Testing&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Run your app and go to create a page&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610180362%2Flaravel%2520form%2520validation%2F2_siuu4z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610180362%2Flaravel%2520form%2520validation%2F2_siuu4z.png" alt="create project"&gt;&lt;/a&gt; &lt;br&gt;
Try to submit a form with values which violates the rules of our validation and try to submit&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610181396%2Flaravel%2520form%2520validation%2F3_gx8i4e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1610181396%2Flaravel%2520form%2520validation%2F3_gx8i4e.png" alt="create page with errors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me for more of my articles, you can leave comments, suggestions, and reactions.&lt;br&gt;
I am open to any vacancy as a PHP (Laravel) backend engineer, I am also available for any job. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for your time&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Schedule a task to run at a specific time in laravel (CronJob)</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Fri, 25 Dec 2020 14:23:32 +0000</pubDate>
      <link>https://forem.com/kingsconsult/schedule-a-task-to-run-at-a-specific-time-in-laravel-cronjob-5aaf</link>
      <guid>https://forem.com/kingsconsult/schedule-a-task-to-run-at-a-specific-time-in-laravel-cronjob-5aaf</guid>
      <description>&lt;p&gt;Good day and Merry Xmas,&lt;br&gt;
Today, I am going to teach you how to schedule a task that can run at a specific time, when building an app, sometimes we might want to automate a task like sending out a newsletter daily/weekly/monthly, sending a report to the admin through email at the end of the day etc. All these task cannot be done manually, so we need a way to schedule it to run at a specific time of the day, week, month, or even every minute, so just relax and let's dive into it&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Setup a new Laravel App&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Install laravel&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer create-project laravel/laravel laraveljobscheduler &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608900621%2FSchedule%2520Job%2F1_xnv91p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608900621%2FSchedule%2520Job%2F1_xnv91p.png" alt="installing laravel 8"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;2. Change into the directory&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cd laraveljobscheduler/&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608900624%2FSchedule%2520Job%2F2_swcc1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608900624%2FSchedule%2520Job%2F2_swcc1a.png" alt="change to the directory"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Setup Mail&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For more explanation of this step, visit my previous article &lt;a href="https://dev.to/kingsconsult/how-to-send-email-in-laravel-8-downwards-using-gmail-3hid"&gt;How to send email in Laravel 8 downwards using Gmail&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608900624%2FSchedule%2520Job%2F3_xjtiyx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608900624%2FSchedule%2520Job%2F3_xjtiyx.png" alt=".env file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Setup our Gmail Mailable&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For more explanation of this step, visit my previous article &lt;a href="https://dev.to/kingsconsult/how-to-send-email-in-laravel-8-downwards-using-gmail-3hid"&gt;How to send email in Laravel 8 downwards using Gmail&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;1. Make the mail&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan make:mail Gmail&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class Gmail extends Mailable
{
    use Queueable, SerializesModels;

    public $details;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($details)
    {
        $this-&amp;gt;details = $details;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this-&amp;gt;subject('Mail from Laravel Job Scheduler')
            -&amp;gt;view('emails.gmail')
            -&amp;gt;from('Kingsconsult001@gmail.com');
    }
}


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;2. Create the view&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;kings&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;{{ $details['title'] }}&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;{{ $details['body'] }}&amp;lt;/p&amp;gt;

    &amp;lt;p&amp;gt;Thank you for subscribing&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Create a Job to send the mail&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We are going to use a Job to send the mail, so we are going to create a job&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan make:job SendEmailJob&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A new folder called &lt;strong&gt;Jobs&lt;/strong&gt; will be created at &lt;strong&gt;app/&lt;/strong&gt;, so subsequently new jobs will be stored in this folder, &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608900618%2FSchedule%2520Job%2F5_uy1tbp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608900618%2FSchedule%2520Job%2F5_uy1tbp.png" alt="new job"&gt;&lt;/a&gt;&lt;br&gt;
Let's modify it to send out our mail &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?php

namespace App\Jobs;

use App\Mail\Gmail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;

class SendEmailJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        $details = [
            'title' =&amp;gt; 'Thank you for subscribing to my newsletter',
            'body' =&amp;gt; 'You will receive a newsletter every Fourth Friday of the month'

        ];
        Mail::to('kingsconsult001@gmail.com')-&amp;gt;send(new Gmail($details));
    }
}


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

&lt;/div&gt;

&lt;p&gt;When calling a Job, the code inside the &lt;strong&gt;handle()&lt;/strong&gt; method will be the one to run, so that is why we write our code in the handle() method.&lt;br&gt;
From the code above, we import our Mail and Gmail class, we then pass the details of our mail to the Gmail class, my article on Sending mail explains this.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Schedule the job to run at the specific time&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Lastly, We need to schedule when the job will be run, in order to do this, we are going to add the code in &lt;strong&gt;app/Console/Kernel.php&lt;/strong&gt;, so let's modify the &lt;strong&gt;schedule()&lt;/strong&gt; method&lt;br&gt;
import these classes before the Kernel class&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;use App\Jobs\SendEmailJob;&lt;br&gt;
use Carbon\Carbon;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;protected function schedule(Schedule $schedule)&lt;br&gt;
    {&lt;br&gt;
        // $schedule-&amp;gt;command('inspire')-&amp;gt;hourly();&lt;br&gt;
            $now = Carbon::now();&lt;br&gt;
        $month = $now-&amp;gt;format('F');&lt;br&gt;
        $year = $now-&amp;gt;format('yy');&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $fourthFridayMonthly = new Carbon('fourth friday of ' . $month . ' ' . $year);

    $schedule-&amp;gt;job(new SendEmailJob)-&amp;gt;monthlyOn($fourthFridayMonthly-&amp;gt;format('d'), '13:46');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;From the code above, We want to send out the newsletter every fourth Fridays of the month at 13:46 GMT, I used that day and time so that I will be able to test if my code works, 
First, I initialize the present time and extract the month and year, then I assign it to a variable, from the variable I created a time that will run every fourth Friday of the present month and year. 
Finally, schedule the job which runs monthly at the day and time that we specified.
**Testing**
Run the scheduler on the terminal
&amp;gt; php artisan schedule:work

![php artisan schedule:work](https://res.cloudinary.com/kingsconsult/image/upload/v1608900618/Schedule%20Job/7_eggcgk.png)
This is the mail I got in my box
![inbox](https://res.cloudinary.com/kingsconsult/image/upload/v1608900625/Schedule%20Job/6_folv46.png)

The complete code can be found in this github repo [Kingsconsult/laravel-schedule-job](https://github.com/Kingsconsult/laravel-schedule-job)

Follow me for more of my articles, you can leave comments, suggestions, and reactions.
I am open to any vacancy as a PHP (Laravel) backend engineer, I am also available for any job. 

[click the link to view my profile and follow me] (https://dev.to/kingsconsult)

Thank you for your time
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>webdev</category>
      <category>aws</category>
    </item>
    <item>
      <title>Customize Laravel Jetstream (Registration and Login)</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Thu, 17 Dec 2020 00:15:44 +0000</pubDate>
      <link>https://forem.com/kingsconsult/customize-laravel-jetstream-registration-and-login-210f</link>
      <guid>https://forem.com/kingsconsult/customize-laravel-jetstream-registration-and-login-210f</guid>
      <description>&lt;p&gt;Hello, welcome back to my series, previously, I wrote on how to &lt;a href="https://dev.to/kingsconsult/customize-laravel-auth-laravel-breeze-registration-and-login-1769"&gt;Customize Laravel Auth (Laravel Breeze Registration and Login)&lt;/a&gt;, this is for those that use &lt;a href="https://dev.to/kingsconsult/how-to-setup-basic-laravel-app-with-login-and-registration-using-laravel-breeze-6o5"&gt;Laravel breeze&lt;/a&gt; for Authentification, but some of my readers who used &lt;a href="https://dev.to/kingsconsult/laravel-8-auth-registration-and-login-32jl"&gt;Laravel Jetstream&lt;/a&gt; are still finding it difficult to customize the Registration and Login process in order to suit their needs.&lt;br&gt;
For those that did not read the previous article, what we are trying to achieve is to customize the Registration and Login whereby a developer can choose to use &lt;strong&gt;username and password&lt;/strong&gt; for &lt;strong&gt;login&lt;/strong&gt; different from the default &lt;strong&gt;email and password&lt;/strong&gt;, this is because some of the users of your application might not be having email address, so the person might use username for the registration and be using it for login.&lt;br&gt;
without further ado, let's dive into the stuff of the day, if you read &lt;a href="https://dev.to/kingsconsult/customize-laravel-auth-laravel-breeze-registration-and-login-1769/edit"&gt;Customize Laravel Auth (Laravel Breeze Registration and Login)&lt;/a&gt;, most of the steps are similar.&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Edit the CreateNewUser.php&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you scaffold your authentication using Laravel Jetstream and installed livewire or inertia, you will have an Action folder in your App directory, and also a Fortify directory inside the Action with some files.&lt;br&gt;
Go to &lt;strong&gt;app/Actions/Fortify/CreateNewUser.php&lt;/strong&gt; customize the &lt;strong&gt;create&lt;/strong&gt; method to this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  public function create(array $input)
    {
        Validator::make($input, [
            'firstname' =&amp;gt; ['required', 'string', 'max:255'],
            'lastname' =&amp;gt; ['required', 'string', 'max:255'],
            'username' =&amp;gt; ['required', 'string', 'max:255'],
            'password' =&amp;gt; $this-&amp;gt;passwordRules(),
        ])-&amp;gt;validate();

        return User::create([
            'firstname' =&amp;gt; $input['firstname'],
            'lastname' =&amp;gt; $input['lastname'],
            'username' =&amp;gt; $input['username'],
            'email' =&amp;gt; $input['email'],
            'password' =&amp;gt; Hash::make($input['password']),
        ]);
    }


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

&lt;/div&gt;

&lt;p&gt;In the &lt;strong&gt;validate( )&lt;/strong&gt; method, I removed &lt;strong&gt;email&lt;/strong&gt;, and added &lt;strong&gt;firstname&lt;/strong&gt;, &lt;strong&gt;lastname&lt;/strong&gt; and &lt;strong&gt;username&lt;/strong&gt;. Also in the &lt;strong&gt;User::create&lt;/strong&gt;, I added the new fields.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Create another migration file to add the new fields to the User table&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan make:migration add_more_fields_to_users_table --table=users&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A migrations file will be created, go to &lt;strong&gt;database/migrations/&lt;/strong&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607940662%2Flaravel%2520breeze%2Fjetstream%2F1_drvf4y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607940662%2Flaravel%2520breeze%2Fjetstream%2F1_drvf4y.png" alt="Migration files"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Add the new fields and modify the name field&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We are going to modify the existing name field with firstname and also add other fields, but to modify an existing fields, we need a package &lt;strong&gt;doctrine/dbal&lt;/strong&gt;, The Doctrine DBAL library is used to determine the current state of the column and to create the SQL queries needed to make the requested changes to your column. &lt;a href="https://laravel.com/docs/8.x/migrations#prerequisites" rel="noopener noreferrer"&gt;Laravel docs&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer require doctrine/dbal&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After this, update the composer, by running the command below&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer update&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607643312%2Flaravel%2520breeze%2Fnew%2F2_g4690b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607643312%2Flaravel%2520breeze%2Fnew%2F2_g4690b.png" alt="php artisan command"&gt;&lt;/a&gt;&lt;br&gt;
Then add the following fields to the &lt;strong&gt;up( )&lt;/strong&gt; method of the migration file created above&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table-&amp;gt;renameColumn('name', 'firstname');
            $table-&amp;gt;string('lastname');
            $table-&amp;gt;string('username')-&amp;gt;unique();
            $table-&amp;gt;string('email')-&amp;gt;nullable()-&amp;gt;change();
        });
    }


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

&lt;/div&gt;

&lt;p&gt;You will notice how we are going to rename our name field to firstname and added lastname and username, we made the username to be unique() and also modify email from mandatory to nullable().&lt;/p&gt;

&lt;p&gt;Finally, run the migration command&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan migrate&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607942115%2Flaravel%2520breeze%2Fjetstream%2F3_kqzrml.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607942115%2Flaravel%2520breeze%2Fjetstream%2F3_kqzrml.png" alt="php artisan migrate"&gt;&lt;/a&gt;&lt;br&gt;
Database &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607942297%2Flaravel%2520breeze%2Fjetstream%2F4_zygi3i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607942297%2Flaravel%2520breeze%2Fjetstream%2F4_zygi3i.png" alt="Database"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Modify the Users Model&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We need to add the fields to be fill in users model, go to &lt;strong&gt;app/Models/User.php&lt;/strong&gt; and edit the &lt;strong&gt;protected $fillable&lt;/strong&gt; to add the new fields&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    protected $fillable = [
        'firstname',
        'email',
        'password',
        'username',
        'lastname'
    ];


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Modify the Registration view&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;resources/views/auth/register.blade.php&lt;/strong&gt; and modify to this&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;x-guest-layout&amp;gt;
    &amp;lt;x-jet-authentication-card&amp;gt;
        &amp;lt;x-slot name="logo"&amp;gt;
            &amp;lt;x-jet-authentication-card-logo /&amp;gt;
        &amp;lt;/x-slot&amp;gt;

        &amp;lt;x-jet-validation-errors class="mb-4" /&amp;gt;

        &amp;lt;form method="POST" action="{{ route('register') }}"&amp;gt;
            @csrf

            &amp;lt;div&amp;gt;
                &amp;lt;x-jet-label value="{{ __('First Name') }}" /&amp;gt;
                &amp;lt;x-jet-input class="block mt-1 w-full" type="text" name="firstname" :value="old('firstname')" required autofocus autocomplete="firstname" /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div&amp;gt;
                &amp;lt;x-jet-label value="{{ __('Last Name') }}" /&amp;gt;
                &amp;lt;x-jet-input class="block mt-1 w-full" type="text" name="lastname" :value="old('lastname')" required autocomplete="lastname" /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div&amp;gt;
                &amp;lt;x-jet-label value="{{ __('Username') }}" /&amp;gt;
                &amp;lt;x-jet-input class="block mt-1 w-full" type="text" name="username" :value="old('username')" autocomplete="username" /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="mt-4"&amp;gt;
                &amp;lt;x-jet-label value="{{ __('Email') }}" /&amp;gt;
                &amp;lt;x-jet-input class="block mt-1 w-full" type="email" name="email" :value="old('email')"  /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="mt-4"&amp;gt;
                &amp;lt;x-jet-label value="{{ __('Password') }}" /&amp;gt;
                &amp;lt;x-jet-input class="block mt-1 w-full" type="password" name="password" required autocomplete="new-password" /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="mt-4"&amp;gt;
                &amp;lt;x-jet-label value="{{ __('Confirm Password') }}" /&amp;gt;
                &amp;lt;x-jet-input class="block mt-1 w-full" type="password" name="password_confirmation" required autocomplete="new-password" /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="flex items-center justify-end mt-4"&amp;gt;
                &amp;lt;a class="underline text-sm text-gray-600 hover:text-gray-900" href="{{ route('login') }}"&amp;gt;
                    {{ __('Already registered?') }}
                &amp;lt;/a&amp;gt;

                &amp;lt;x-jet-button class="ml-4"&amp;gt;
                    {{ __('Register') }}
                &amp;lt;/x-jet-button&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/x-jet-authentication-card&amp;gt;
&amp;lt;/x-guest-layout&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;Start our application with &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan serve&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Click on Register, we are going to have this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607644836%2Flaravel%2520breeze%2Fnew%2F5_wuabwr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607644836%2Flaravel%2520breeze%2Fnew%2F5_wuabwr.png" alt="register"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 6: Modify the Login view&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;resources/views/auth/login.blade.php&lt;/strong&gt; and modify to this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;x-guest-layout&amp;gt;
    &amp;lt;x-jet-authentication-card&amp;gt;
        &amp;lt;x-slot name="logo"&amp;gt;
            &amp;lt;x-jet-authentication-card-logo /&amp;gt;
        &amp;lt;/x-slot&amp;gt;

        &amp;lt;x-jet-validation-errors class="mb-4" /&amp;gt;

        @if (session('status'))
        &amp;lt;div class="mb-4 font-medium text-sm text-green-600"&amp;gt;
            {{ session('status') }}
        &amp;lt;/div&amp;gt;
        @endif

        &amp;lt;form method="POST" action="{{ route('login') }}"&amp;gt;
            @csrf

            &amp;lt;div&amp;gt;
                &amp;lt;x-jet-label value="{{ __('Username') }}" /&amp;gt;
                &amp;lt;x-jet-input class="block mt-1 w-full" type="text" name="username" :value="old('username')" required autofocus /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="mt-4"&amp;gt;
                &amp;lt;x-jet-label value="{{ __('Password') }}" /&amp;gt;
                &amp;lt;x-jet-input class="block mt-1 w-full" type="password" name="password" required autocomplete="current-password" /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="block mt-4"&amp;gt;
                &amp;lt;label class="flex items-center"&amp;gt;
                    &amp;lt;input type="checkbox" class="form-checkbox" name="remember"&amp;gt;
                    &amp;lt;span class="ml-2 text-sm text-gray-600"&amp;gt;{{ __('Remember me') }}&amp;lt;/span&amp;gt;
                &amp;lt;/label&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="flex items-center justify-end mt-4"&amp;gt;
                @if (Route::has('password.request'))
                &amp;lt;a class="underline text-sm text-gray-600 hover:text-gray-900" href="{{ route('password.request') }}"&amp;gt;
                    {{ __('Forgot your password?') }}
                &amp;lt;/a&amp;gt;
                @endif

                &amp;lt;x-jet-button class="ml-4"&amp;gt;
                    {{ __('Login') }}
                &amp;lt;/x-jet-button&amp;gt;
            &amp;lt;/div&amp;gt; 
        &amp;lt;/form&amp;gt;
    &amp;lt;/x-jet-authentication-card&amp;gt;
&amp;lt;/x-guest-layout&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;We removed &lt;strong&gt;email&lt;/strong&gt; field and replace it with &lt;strong&gt;username&lt;/strong&gt; field&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 7: Modify the Fortify configuration file&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We are going to specify what we are going to be using for the login, so go to &lt;strong&gt;config/fortify.php&lt;/strong&gt;, you will see an array, find the &lt;strong&gt;username&lt;/strong&gt; key and change it to &lt;strong&gt;username&lt;/strong&gt; from &lt;strong&gt;email&lt;/strong&gt;,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  'username' =&amp;gt; 'username',


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

&lt;/div&gt;

&lt;p&gt;Then clear your config and cache&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan config:cache&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Run your app in case it is down&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan serve&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608163909%2Flaravel%2520breeze%2Fjetstream%2F5_l7uchc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608163909%2Flaravel%2520breeze%2Fjetstream%2F5_l7uchc.png" alt="Login page"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608163908%2Flaravel%2520breeze%2Fjetstream%2F6_vtw6rp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1608163908%2Flaravel%2520breeze%2Fjetstream%2F6_vtw6rp.png" alt="Dashboard after login"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can now login with username and password instead of email address. That is all&lt;br&gt;
Follow me for more of my articles, you can leave comments, suggestions, and reactions.&lt;br&gt;
I am open to any vacancy as a PHP backend engineer, my strength is in the Laravel framework.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

</description>
      <category>jetstream</category>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Customize Laravel Auth (Laravel Breeze Registration and Login)</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Thu, 10 Dec 2020 22:36:42 +0000</pubDate>
      <link>https://forem.com/kingsconsult/customize-laravel-auth-laravel-breeze-registration-and-login-1769</link>
      <guid>https://forem.com/kingsconsult/customize-laravel-auth-laravel-breeze-registration-and-login-1769</guid>
      <description>&lt;p&gt;Hello Artisans, after making a post on &lt;a href="https://dev.to/kingsconsult/how-to-setup-basic-laravel-app-with-login-and-registration-using-laravel-breeze-6o5"&gt;Basic Laravel Login and Registration using Laravel Breeze&lt;/a&gt;, I got a lot of private messages on how to customize the Registration and Login where a developer can be able to add more fields because the default Laravel User Registration fields are just limited to &lt;strong&gt;Name&lt;/strong&gt;, &lt;strong&gt;Email&lt;/strong&gt; and &lt;strong&gt;Password&lt;/strong&gt; right from the time of the Legacy UI till the time of writing this report. But there are instances of where a developer might want to collect not just the name, but &lt;strong&gt;First Name&lt;/strong&gt;, &lt;strong&gt;Last Name&lt;/strong&gt;, &lt;strong&gt;Username&lt;/strong&gt;, &lt;strong&gt;Password&lt;/strong&gt; or even making the &lt;strong&gt;Email&lt;/strong&gt; not mandatory for users who don't have email, so I decide to write this little piece.&lt;br&gt;
For this article, I am going to use the app from this article &lt;a href="https://dev.to/kingsconsult/how-to-setup-basic-laravel-app-with-login-and-registration-using-laravel-breeze-6o5"&gt;Basic Laravel Login and Registration using Laravel Breeze&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Edit the RegisteredUserController&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;app/Http/Controllers/Auth/RegisteredUserController.php&lt;/strong&gt; and customize the &lt;strong&gt;store&lt;/strong&gt; method to this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    public function store(Request $request)
    {
        $request-&amp;gt;validate([
            'firstname' =&amp;gt; 'required|string|max:255',
            'lastname' =&amp;gt; 'required|string|max:255',
            'password' =&amp;gt; 'required|string|confirmed|min:8',
            'username' =&amp;gt; 'required|string|max:255',
        ]);

        Auth::login($user = User::create([
            'firstname' =&amp;gt; $request-&amp;gt;firstname,
            'lastname' =&amp;gt; $request-&amp;gt;lastname,
            'username' =&amp;gt; $request-&amp;gt;username,
            'email' =&amp;gt; $request-&amp;gt;email,
            'password' =&amp;gt; Hash::make($request-&amp;gt;password),
        ]));

        event(new Registered($user));

        return redirect(RouteServiceProvider::HOME);
    }


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

&lt;/div&gt;

&lt;p&gt;In the &lt;strong&gt;validate( )&lt;/strong&gt; method, I removed &lt;strong&gt;email&lt;/strong&gt;, and added &lt;strong&gt;firstname&lt;/strong&gt;, &lt;strong&gt;lastname&lt;/strong&gt; and &lt;strong&gt;username&lt;/strong&gt;. Also in the &lt;strong&gt;User::create&lt;/strong&gt;, I added the new fields.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Create another migration file to add the new fields to the User and login_history table&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This migration field will add the new fields to our existing &lt;strong&gt;users&lt;/strong&gt; table, so run the command below&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan make:migration add_more_fields_to_users_table --table=users&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Do the same for the login_history table.&lt;br&gt;
The &lt;strong&gt;--table=users&lt;/strong&gt; flag will specify the type of schema facade to use.&lt;br&gt;
A migrations file will be created, go to &lt;strong&gt;database/migrations/&lt;/strong&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607641943%2Flaravel%2520breeze%2Fnew%2F1_gfffcc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607641943%2Flaravel%2520breeze%2Fnew%2F1_gfffcc.png" alt="Migration files"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Add the new fields and modify the name field&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We are going to modify the existing name field with firstname and also add other fields, but to modify an existing fields, we need a package &lt;strong&gt;doctrine/dbal&lt;/strong&gt;, The Doctrine DBAL library is used to determine the current state of the column and to create the SQL queries needed to make the requested changes to your column. &lt;a href="https://laravel.com/docs/8.x/migrations#prerequisites" rel="noopener noreferrer"&gt;Laravel docs&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer require doctrine/dbal&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After this, update the composer, by running the command below&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer update&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607643312%2Flaravel%2520breeze%2Fnew%2F2_g4690b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607643312%2Flaravel%2520breeze%2Fnew%2F2_g4690b.png" alt="php artisan command"&gt;&lt;/a&gt;&lt;br&gt;
Then add the following fields to the &lt;strong&gt;up( )&lt;/strong&gt; method of the migration file created above&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table-&amp;gt;renameColumn('name', 'firstname');
            $table-&amp;gt;string('lastname');
            $table-&amp;gt;string('username');
            $table-&amp;gt;string('email')-&amp;gt;nullable()-&amp;gt;change();
        });
    }


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

&lt;/div&gt;

&lt;p&gt;You will notice how we are going to rename our name field to firstname and added lastname and username, also we modify file email from mandatory to nullable().&lt;/p&gt;

&lt;p&gt;Don't forget to do the same for the login_history.&lt;br&gt;
Finally, run the migration command, but  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan migrate&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607643462%2Flaravel%2520breeze%2Fnew%2F3_e8y5ua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607643462%2Flaravel%2520breeze%2Fnew%2F3_e8y5ua.png" alt="php artisan migrate"&gt;&lt;/a&gt;&lt;br&gt;
Database &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607643667%2Flaravel%2520breeze%2Fnew%2F4_ypf2pa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607643667%2Flaravel%2520breeze%2Fnew%2F4_ypf2pa.png" alt="Database"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Modify the Users Model&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We need to add the fields to be fill in users model, go to &lt;strong&gt;app/Models/User.php&lt;/strong&gt; and edit the &lt;strong&gt;protected $fillable&lt;/strong&gt; to add the new fields&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    protected $fillable = [
        'firstname',
        'email',
        'password',
        'username',
        'lastname'
    ];


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Modify the Registration view&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;resources/views/auth/register.blade.php&lt;/strong&gt; and modify to this&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;x-guest-layout&amp;gt;
    &amp;lt;x-auth-card&amp;gt;
        &amp;lt;x-slot name="logo"&amp;gt;
            &amp;lt;a href="/"&amp;gt;
                &amp;lt;x-application-logo class="w-20 h-20 fill-current text-gray-500" /&amp;gt;
            &amp;lt;/a&amp;gt;
        &amp;lt;/x-slot&amp;gt;

        &amp;lt;!-- Validation Errors --&amp;gt;
        &amp;lt;x-auth-validation-errors class="mb-4" :errors="$errors" /&amp;gt;

        &amp;lt;form method="POST" action="{{ route('register') }}"&amp;gt;
            @csrf

            &amp;lt;!-- Name --&amp;gt;
            &amp;lt;div&amp;gt;
                &amp;lt;x-label for="firstname" :value="__('First Name')" /&amp;gt;

                &amp;lt;x-input id="firstname" class="block mt-1 w-full" type="text" name="firstname" required autofocus /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;!-- Name --&amp;gt;
            &amp;lt;div&amp;gt;
                &amp;lt;x-label for="lastname" :value="__('Last Name')" /&amp;gt;

                &amp;lt;x-input id="lastname" class="block mt-1 w-full" type="text" name="lastname" required /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;!-- Name --&amp;gt;
            &amp;lt;div&amp;gt;
                &amp;lt;x-label for="username" :value="__('username')" /&amp;gt;

                &amp;lt;x-input id="username" class="block mt-1 w-full" type="text" name="username" required /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;!-- Email Address --&amp;gt;
            &amp;lt;div class="mt-4"&amp;gt;
                &amp;lt;x-label for="email" :value="__('Email')" /&amp;gt;

                &amp;lt;x-input id="email" class="block mt-1 w-full" type="email" name="email"  /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;!-- Password --&amp;gt;
            &amp;lt;div class="mt-4"&amp;gt;
                &amp;lt;x-label for="password" :value="__('Password')" /&amp;gt;

                &amp;lt;x-input id="password" class="block mt-1 w-full" type="password" name="password" required autocomplete="new-password" /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;!-- Confirm Password --&amp;gt;
            &amp;lt;div class="mt-4"&amp;gt;
                &amp;lt;x-label for="password_confirmation" :value="__('Confirm Password')" /&amp;gt;

                &amp;lt;x-input id="password_confirmation" class="block mt-1 w-full" type="password" name="password_confirmation" required /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="flex items-center justify-end mt-4"&amp;gt;
                &amp;lt;x-button&amp;gt;
                    {{ __('Register') }}
                &amp;lt;/x-button&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/x-auth-card&amp;gt;
&amp;lt;/x-guest-layout&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;Start our application with &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan serve&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Click on Register, we are going to have this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607644836%2Flaravel%2520breeze%2Fnew%2F5_wuabwr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607644836%2Flaravel%2520breeze%2Fnew%2F5_wuabwr.png" alt="register"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 6: Modify the Login view&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;resources/views/auth/login.blade.php&lt;/strong&gt; and modify to this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;x-guest-layout&amp;gt;
    &amp;lt;x-auth-card&amp;gt;
        &amp;lt;x-slot name="logo"&amp;gt;
            &amp;lt;a href="/"&amp;gt;
                &amp;lt;x-application-logo class="w-20 h-20 fill-current text-gray-500" /&amp;gt;
            &amp;lt;/a&amp;gt;
        &amp;lt;/x-slot&amp;gt;

        &amp;lt;!-- Session Status --&amp;gt;
        &amp;lt;x-auth-session-status class="mb-4" :status="session('status')" /&amp;gt;

        &amp;lt;!-- Validation Errors --&amp;gt;
        &amp;lt;x-auth-validation-errors class="mb-4" :errors="$errors" /&amp;gt;

        &amp;lt;form method="POST" action="{{ route('login') }}"&amp;gt;
            @csrf

            &amp;lt;!-- Email Address --&amp;gt;
            &amp;lt;div&amp;gt;
                &amp;lt;x-label for="username" :value="__('Username')" /&amp;gt;

                &amp;lt;x-input id="username" class="block mt-1 w-full" type="text" name="username" required autofocus /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;!-- Password --&amp;gt;
            &amp;lt;div class="mt-4"&amp;gt;
                &amp;lt;x-label for="password" :value="__('Password')" /&amp;gt;

                &amp;lt;x-input id="password" class="block mt-1 w-full" type="password" name="password" required autocomplete="current-password" /&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;!-- Remember Me --&amp;gt;
            &amp;lt;div class="block mt-4"&amp;gt;
                &amp;lt;label for="remember_me" class="flex items-center"&amp;gt;
                    &amp;lt;input id="remember_me" type="checkbox" class="form-checkbox" name="remember"&amp;gt;
                    &amp;lt;span class="ml-2 text-sm text-gray-600"&amp;gt;{{ __('Remember me') }}&amp;lt;/span&amp;gt;
                &amp;lt;/label&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="flex items-center justify-end mt-4"&amp;gt;
                @if (Route::has('password.request'))
                &amp;lt;a class="underline text-sm text-gray-600 hover:text-gray-900" href="{{ route('password.request') }}"&amp;gt;
                    {{ __('Forgot your password?') }}
                &amp;lt;/a&amp;gt;
                @endif

                &amp;lt;x-button class="ml-3"&amp;gt;
                    {{ __('Login') }}
                &amp;lt;/x-button&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/x-auth-card&amp;gt;
&amp;lt;/x-guest-layout&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;This will change the login field from email to username&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 7: Modify the Login Request Class&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is the class that replaces the &lt;strong&gt;LoginController&lt;/strong&gt; class in the previous Laravel Authentication. Go to &lt;strong&gt;app/Requests/Auth/LoginRequest.php&lt;/strong&gt; and change all the email string to username string, and also make sure the validating rules, you remove the email rule and replace it with username rule&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?php

namespace App\Http\Requests\Auth;

use Illuminate\Auth\Events\Lockout;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use App\Events\LoginHistory;



class LoginRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username' =&amp;gt; 'required|string',
            'password' =&amp;gt; 'required|string',
        ];
    }

    /**
     * Attempt to authenticate the request's credentials.
     *
     * @return void
     *
     * @throws \Illuminate\Validation\ValidationException
     */
    public function authenticate()
    {
        $this-&amp;gt;ensureIsNotRateLimited();

        if (! Auth::attempt($this-&amp;gt;only('username', 'password'), $this-&amp;gt;filled('remember'))) {
            RateLimiter::hit($this-&amp;gt;throttleKey());

            throw ValidationException::withMessages([
                'username' =&amp;gt; __('auth.failed'),
            ]);
        }

        $user = Auth::user();

        event(new LoginHistory($user));

        RateLimiter::clear($this-&amp;gt;throttleKey());
    }

    /**
     * Ensure the login request is not rate limited.
     *
     * @return void
     *
     * @throws \Illuminate\Validation\ValidationException
     */
    public function ensureIsNotRateLimited()
    {
        if (! RateLimiter::tooManyAttempts($this-&amp;gt;throttleKey(), 5)) {
            return;
        }

        event(new Lockout($this));

        $seconds = RateLimiter::availableIn($this-&amp;gt;throttleKey());

        throw ValidationException::withMessages([
            'username' =&amp;gt; trans('auth.throttle', [
                'seconds' =&amp;gt; $seconds,
                'minutes' =&amp;gt; ceil($seconds / 60),
            ]),
        ]);
    }

    /**
     * Get the rate limiting throttle key for the request.
     *
     * @return string
     */
    public function throttleKey()
    {
        return Str::lower($this-&amp;gt;input('username')).'|'.$this-&amp;gt;ip();
    }
}


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

&lt;/div&gt;

&lt;p&gt;Logout from the app and click on login&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607650504%2Flaravel%2520breeze%2Fnew%2F6_d0sdcc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607650504%2Flaravel%2520breeze%2Fnew%2F6_d0sdcc.png" alt="login page"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607650645%2Flaravel%2520breeze%2Fnew%2F7_fm8xwc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1607650645%2Flaravel%2520breeze%2Fnew%2F7_fm8xwc.png" alt="dashboard after login"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can now login with username and password instead of email address. That is all&lt;br&gt;
Follow me for more of my articles, you can leave comments, suggestions, and reactions.&lt;br&gt;
I am open to any vacancy as a PHP backend engineer, my strength is in the Laravel framework &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Pagination from Array in Laravel 8</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Thu, 03 Dec 2020 22:56:01 +0000</pubDate>
      <link>https://forem.com/kingsconsult/pagination-from-array-in-laravel-8-4fg5</link>
      <guid>https://forem.com/kingsconsult/pagination-from-array-in-laravel-8-4fg5</guid>
      <description>&lt;p&gt;Hello, Today I am going to be showing you how to create pagination in laravel from an array, sometimes we might find ourselves in a situation where we need to do some manipulation from the query result we got from the database or from an API before sending it to the view, if the array contains so many data, it might be cumbersome and messy to just populate it on a single page.&lt;br&gt;
Laravel has a built-in function for pagination that is already integrated to Query builder and Eloquent ORM results of database which can be easily called like&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$users = DB::table('users')-&amp;gt;paginate(15);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But it cannot be applied to an array, so sit tight, we are going to be creating our own pagination from an array collection.&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;

&lt;p&gt;For this article, I will be using code from my previous article on &lt;a href="https://dev.to/kingsconsult/how-to-consume-restful-apis-in-laravel-8-and-laravel-7-4gii"&gt;How to consume RESTful APIs in Laravel 8&lt;/a&gt;, what I want to do is grab the contents of an API (Github public API), extract some data, and store it in an array, then paginate the array and send it to the view (frontend).&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Setup your app&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In case you don't have a laravel app running, you can click on this &lt;a href="https://dev.to/kingsconsult/how-to-consume-restful-apis-in-laravel-8-and-laravel-7-4gii"&gt;Link&lt;/a&gt;, and checkout step one on how to set up a laravel app.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Add route&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;routes/web.php&lt;/strong&gt; and add the route to view our paginated array&lt;/p&gt;

&lt;blockquote&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::get('createpagination', [ProjectController::class, 'createPagination'])-&amp;gt;name('createPagination');
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Create Controller Methods&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Add the following methods to the &lt;strong&gt;app/Http/Controllers/ProjectController.php&lt;/strong&gt;&lt;br&gt;
Call the class at the top before the ProjectController Class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add this inside the class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    private function paginate($items, $perPage = 5, $page = null, $options = [])
    {
        $page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
        $items = $items instanceof Collection ? $items : Collection::make($items);

        return new LengthAwarePaginator($items-&amp;gt;forPage($page, $perPage), $items-&amp;gt;count(), $perPage, $page, $options);
    }

    public function createPagination() 
    {
        $client = new Client(); //GuzzleHttp\Client
        // Github public API to view my public Repositories
        $url = "https://api.github.com/users/kingsconsult/repos";


        $response = $client-&amp;gt;request('GET', $url, [
            'verify'  =&amp;gt; false,
        ]);
        $responseBody = json_decode($response-&amp;gt;getBody());

        // Extract key, name, URL and date the repo was created
        // and store it in an array
        $responseArray = [];
        foreach ($responseBody as $key =&amp;gt; $views) {
            $array = array('id' =&amp;gt; $key, 'name' =&amp;gt; $views-&amp;gt;name, 'url' =&amp;gt; $views-&amp;gt;url, 'created_at' =&amp;gt; $views-&amp;gt;created_at);
            array_push($responseArray, $array);
        }

        // use the paginate method that we created to paginate the array and also 
        // add the URL for the other pages using setPath() method
        $githubRepo = $this-&amp;gt;paginate($responseArray)-&amp;gt;setPath('/projects/createpagination');

        return view('projects.createpagination', compact('githubRepo'))
        -&amp;gt;with('i', (request()-&amp;gt;input('page', 1) - 1) * 5)
        ;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Create View&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;resources/views/projects&lt;/strong&gt; and create a blade file called &lt;strong&gt;createpagination.blade.php&lt;/strong&gt; and add the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@extends('layouts.app')

@section('content')

&amp;lt;style&amp;gt;

&amp;lt;/style&amp;gt;
&amp;lt;div class="row mb-3"&amp;gt;
    &amp;lt;div class="col-lg-12 margin-tb"&amp;gt;
        &amp;lt;div class="text-center"&amp;gt;
            &amp;lt;h2&amp;gt;Github Public Repository&amp;lt;/h2&amp;gt;
            &amp;lt;a class="btn btn-primary" href="{{ route('projects.index') }}" title="Go back"&amp;gt; &amp;lt;i class="fas fa-backward fa-2x"&amp;gt;&amp;lt;/i&amp;gt; &amp;lt;/a&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;div class="container-fluid mb-5" style="margin-bottom: 150px !important"&amp;gt;
    &amp;lt;div class="row mr-4"&amp;gt;

 &amp;lt;table class="table table-bordered table-responsive-lg"&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;th&amp;gt;No&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Url&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Date Created&amp;lt;/th&amp;gt; 
    &amp;lt;/tr&amp;gt;
    @foreach ($githubRepo as $repo)
    &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;{{ ++$i }}&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;{{ $repo['name'] }}&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;{{ $repo['url'] }}&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;{{ $repo['created_at'] }}&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    @endforeach
&amp;lt;/table&amp;gt;
{!! $githubRepo-&amp;gt;links() !!}
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;


@endsection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Use Bootstrap for the pagination links&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If we don't indicate that we are going to use Boostrap for the pagination, the pagination links will be displaying weird arrows, so to style our pagination links, go to &lt;strong&gt;app/Providers/AppServiceProvider.php&lt;/strong&gt; and tell the app to use Bootstrap in pagination, add this to the boot method&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Paginator::useBootstrap();&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and at the top, add this also&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;use Illuminate\Pagination\Paginator;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rR36xFnK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/kingsconsult/image/upload/v1607044614/paginate_elwn5j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rR36xFnK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/kingsconsult/image/upload/v1607044614/paginate_elwn5j.png" alt="http://127.0.0.1:8000/projects/createpagination?page=3" width="800" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me for more of my articles, you can leave comments, suggestions, and reactions&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>laravel</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Laravel 8 Events and Listeners with Practical Example</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Wed, 25 Nov 2020 22:38:33 +0000</pubDate>
      <link>https://forem.com/kingsconsult/laravel-8-events-and-listeners-with-practical-example-9m7</link>
      <guid>https://forem.com/kingsconsult/laravel-8-events-and-listeners-with-practical-example-9m7</guid>
      <description>&lt;p&gt;Hello, today I want to talk about Events and Listeners in Laravel, in programming to write a scalable, reusable and clean code, you need to follow some programming principles, one of which is &lt;strong&gt;SOLID&lt;/strong&gt;, I will not be going deep into explaining that today, but I will just highlight one, the &lt;strong&gt;S&lt;/strong&gt; which stands for &lt;strong&gt;Single Responsibility Principle&lt;/strong&gt;, this principle states that &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A class should have one and only one reason to change, meaning that a class should have only one job.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What this means is that, &lt;strong&gt;A class should only perform one task&lt;/strong&gt;, many times, we always load our class with some many functionalities, so if the class changes, a lot of things will break in our application, which is not a good practice.&lt;br&gt;
So I will introduce Events and Listeners to help in making our class perform just one task.&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me and get more updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is An Event?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Events are the ways we hook into the activities of our application, it is just a way to observe an activity, for instance, login, a class can be created to monitor the activity of login, when a user logs in, the event class can execute some functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is A Listener?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A Listener is a class that listens to the events that they are mapped to and execute a task, that is they are the ones that perform a given task for an event.&lt;br&gt;
Let me illustrate, you might want to send a welcome email to a new user of your application, and also assign a role to the user based on the information provided in the registration, etc, you would not want to do all those in the RegisterController because that we violate the first principle of SOLID, where the Controller will perform more than one task, the RegisterController needs to only perform the activity of registration of a new user. so an event needs to be carried out in the process of registration, where assigning a role, sending an email, etc are the individual listeners under the event.&lt;br&gt;
For this article, I will write one listener in an event, what the listener will do is to store the login of each user of the app in a table, this is just an illustration that will show you how it works.&lt;br&gt;
If you have a laravel project that has auth already, you can follow immediately, or you can follow my article &lt;a href="https://dev.to/kingsconsult/how-to-setup-basic-laravel-app-with-login-and-registration-using-laravel-breeze-6o5"&gt;Basic Laravel Login and Registration using Laravel Breeze&lt;/a&gt;, I will be using the project on that article from my system.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Register the event and listeners in the EventServiceProvider&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For our events and listeners to work, we must register them in the &lt;strong&gt;EventServiceProvider&lt;/strong&gt; class that has already been set up for us at the time of installing our laravel project. So go to &lt;strong&gt;app/Providers/EventServiceProvider.php&lt;/strong&gt; and click&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606353995%2Flaravel%2520event%2520listeners%2F1_jeqzqt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606353995%2Flaravel%2520event%2520listeners%2F1_jeqzqt.png" alt="EventServiceProvider.php"&gt;&lt;/a&gt;&lt;br&gt;
Events and Listeners are registered as key =&amp;gt; value pair in the &lt;strong&gt;protected $listen&lt;/strong&gt;, from the picture above, an event and a listener is already registered  &lt;strong&gt;Registered::class&lt;/strong&gt; is the event, while &lt;strong&gt;SendEmailVerificationNotification::class&lt;/strong&gt; is the listener, so we are going to add our own&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?php

namespace App\Providers;

use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use App\Events\LoginHistory;
use App\Listeners\storeUserLoginHistory;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class =&amp;gt; [
            SendEmailVerificationNotification::class,
        ],
        LoginHistory::class =&amp;gt; [
            StoreUserLoginHistory::class,
        ]
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}


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

&lt;/div&gt;

&lt;p&gt;We added another event class called &lt;strong&gt;LoginHistory&lt;/strong&gt; and also a listener called &lt;strong&gt;StoreUserLoginHistory&lt;/strong&gt;, and noticed up that we called the class here in this way &lt;strong&gt;use App\Events\LoginHistory;&lt;/strong&gt; and &lt;strong&gt;use App\Listeners\storeUserLoginHistory;&lt;/strong&gt;, don't worry, I know you are wondering that the class does not exist in our application, we are going to generate it in the next step, you can add as many events and listeners as possible like this and even more&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 protected $listen = [
        Event1::class =&amp;gt; [
            Listener1::class,
            Listener2::class
        ],
        Event2::class =&amp;gt; [
            Listener5::class,
            Listener7::class
        ],
        Event3::class =&amp;gt; [
            Listener4::class,
            Listener7::class,
            Listener9::class
        ],
 ];


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Generate Events &amp;amp; Listeners&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Previously, we write classes of events and listeners in the EventServiceProvider, so to generate it at once, we run this command &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan event:generate&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606357716%2Flaravel%2520event%2520listeners%2F2_jhrfdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606357716%2Flaravel%2520event%2520listeners%2F2_jhrfdl.png" alt="generate event"&gt;&lt;/a&gt;&lt;br&gt;
That command will automatically generate all the events and listeners found in the event provider,&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606357984%2Flaravel%2520event%2520listeners%2F3_tux1tt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606357984%2Flaravel%2520event%2520listeners%2F3_tux1tt.png" alt="file structure"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Write the Events and Listener class&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Remember what we are trying to achieve was to store all the login of our app in a table, so click on the &lt;strong&gt;app/Events/LoginHistory.php&lt;/strong&gt; and edit as follows &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

class LoginHistory
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $user;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($user)
    {
        $this-&amp;gt;user = $user;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}


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

&lt;/div&gt;

&lt;p&gt;from the code above, the event accepts the $user which is the information of the user, and it will pass it to the listener.&lt;br&gt;
Click on &lt;strong&gt;app/Listeners/storeUserLoginHistory.php&lt;/strong&gt;, this is where we are going to be writing the main logic of the storing of the login history, inside the handle method, add the following code&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    public function handle(LoginHistory $event)
    {
        $current_timestamp = Carbon::now()-&amp;gt;toDateTimeString();

        $userinfo = $event-&amp;gt;user;

        $saveHistory = DB::table('login_history')-&amp;gt;insert(
            ['name' =&amp;gt; $userinfo-&amp;gt;name, 'email' =&amp;gt; $userinfo-&amp;gt;email, 'created_at' =&amp;gt; $current_timestamp, 'updated_at' =&amp;gt; $current_timestamp]
        );
        return $saveHistory;
    }


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

&lt;/div&gt;

&lt;p&gt;Also remember to call the &lt;strong&gt;Carbon&lt;/strong&gt; and &lt;strong&gt;DB facade&lt;/strong&gt; before the class&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

use Illuminate\Support\Facades\DB;
use Carbon\Carbon;


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

&lt;/div&gt;

&lt;p&gt;Our listener now looks like this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606360110%2Flaravel%2520event%2520listeners%2F4_flrxfu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606360110%2Flaravel%2520event%2520listeners%2F4_flrxfu.png" alt="Listener"&gt;&lt;/a&gt;&lt;br&gt;
From the listener, we are trying to add the name, email, time created and time updated to a table &lt;strong&gt;login_history&lt;/strong&gt;, that is when any user logs in, it will grab that information and store it in the table.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Create the Table and Migrate&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;I am not going to explain deep on this step, I have some of my articles that explain them, check them out from my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt;,&lt;br&gt;
Create migration file&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606361049%2Flaravel%2520event%2520listeners%2F5_vr6oge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606361049%2Flaravel%2520event%2520listeners%2F5_vr6oge.png" alt="create migration file"&gt;&lt;/a&gt;&lt;br&gt;
Add your columns to the migration files&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606361274%2Flaravel%2520event%2520listeners%2F6_ckt2kk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606361274%2Flaravel%2520event%2520listeners%2F6_ckt2kk.png" alt="migration file"&gt;&lt;/a&gt;&lt;br&gt;
Then migrate&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606361973%2Flaravel%2520event%2520listeners%2F7_nspm9b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606361973%2Flaravel%2520event%2520listeners%2F7_nspm9b.png" alt="migrate"&gt;&lt;/a&gt;&lt;br&gt;
We now have our table in the database&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606362355%2Flaravel%2520event%2520listeners%2F8_jifbxe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606362355%2Flaravel%2520event%2520listeners%2F8_jifbxe.png" alt="db"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Dispatch the Event&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is the last step, we need to call the event in the LoginController, if you are using laravel 7, or below, you can create a method in the &lt;strong&gt;LoginController.php&lt;/strong&gt; like this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    protected function authenticated() {

        $user = Auth::user();

        event(new LoginHistory($user));
    }


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

&lt;/div&gt;

&lt;p&gt;but for this article, I am using Laravel Breeze, a simple UI scaffolding that was released 16 days ago, so I will go to &lt;strong&gt;LoginRequest.php&lt;/strong&gt; found in &lt;strong&gt;app/Http/Requests/Auth/LoginRequest.php&lt;/strong&gt; and inside the &lt;strong&gt;authenticate()&lt;/strong&gt; method, I will call my event and pass the $user to the class &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  public function authenticate()
    {
        $this-&amp;gt;ensureIsNotRateLimited();

        if (! Auth::attempt($this-&amp;gt;only('email', 'password'), $this-&amp;gt;filled('remember'))) {
            RateLimiter::hit($this-&amp;gt;throttleKey());

            throw ValidationException::withMessages([
                'email' =&amp;gt; __('auth.failed'),
            ]);
        }

        $user = Auth::user();

        event(new LoginHistory($user));

        RateLimiter::clear($this-&amp;gt;throttleKey());
    }


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

&lt;/div&gt;

&lt;p&gt;I only added &lt;strong&gt;$user = Auth::user();&lt;/strong&gt; and &lt;strong&gt;event(new LoginHistory($user));&lt;/strong&gt;, notice how I dispatched my event, you can use that or you use this &lt;strong&gt;EventClass::dispatch();&lt;/strong&gt;, but we are using &lt;strong&gt;event(new LoginHistory($user));&lt;/strong&gt;.&lt;br&gt;
So when a user attempts to sign in, if the user is authenticated, the event will then be fired, and the listener will save the history&lt;br&gt;
This is the result, when I sign in twice&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606364300%2Flaravel%2520event%2520listeners%2F9_m4fqxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1606364300%2Flaravel%2520event%2520listeners%2F9_m4fqxh.png" alt="db"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me for more of my articles, you can leave comments, suggestions, and reactions.&lt;br&gt;
I am open to any vacancy as a PHP backend engineer, my strength is in the Laravel framework &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for your time&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Laravel Login and Registration using Laravel Breeze</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Mon, 16 Nov 2020 22:40:36 +0000</pubDate>
      <link>https://forem.com/kingsconsult/laravel-login-and-registration-using-laravel-breeze-3aj0</link>
      <guid>https://forem.com/kingsconsult/laravel-login-and-registration-using-laravel-breeze-3aj0</guid>
      <description></description>
    </item>
    <item>
      <title>Basic Laravel Login and Registration using Laravel Breeze</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Sat, 14 Nov 2020 02:17:12 +0000</pubDate>
      <link>https://forem.com/kingsconsult/how-to-setup-basic-laravel-app-with-login-and-registration-using-laravel-breeze-6o5</link>
      <guid>https://forem.com/kingsconsult/how-to-setup-basic-laravel-app-with-login-and-registration-using-laravel-breeze-6o5</guid>
      <description>&lt;p&gt;Hello, How are you doing, I want to introduce Laravel Breeze to you, in the course of the week Taylor Otwell (creator of Laravel) tweeted about a new package released (Laravel Breeze). &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316055%2Flaravel%2520breeze%2F1_d5lqji.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316055%2Flaravel%2520breeze%2F1_d5lqji.png" alt="Taylor Tweet"&gt;&lt;/a&gt; This is because of the uproar about Jetstream where some thought that Laravel have abandoned their legacy UI, but Taylor cleared the air on that, and have to release another package that is not complicated like the Jetstream and in which one can customize to his/her desire. &lt;br&gt;
This comes with basic Authentication like, User registration and user Login, change of password, email setup, send email for change of password, tailwind and blade etc. Let's create our first app with Laravel breeze.&lt;/p&gt;

&lt;p&gt;If you prefer to watch videos, this is the video &lt;a href="https://youtu.be/0S15GNx_32U" rel="noopener noreferrer"&gt;Youtube Video link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Install a new Laravel app&lt;/strong&gt;
&lt;/h3&gt;

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

&lt;blockquote&gt;
&lt;p&gt;laravel new breeze&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316055%2Flaravel%2520breeze%2F2_srninx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316055%2Flaravel%2520breeze%2F2_srninx.png" alt="laravel new breeze"&gt;&lt;/a&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F3_lqm2nf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F3_lqm2nf.png" alt="laravel new breeze"&gt;&lt;/a&gt;&lt;br&gt;
but in using this, you must make sure laravel is installed on your system, you can install laravel globally using&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer global require laravel/installer&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;or you can install laravel using composer without Laravel using&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer create-project laravel/laravel breeze --prefer-dist&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F4_pdx5sk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F4_pdx5sk.png" alt="composer create-project"&gt;&lt;/a&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F5_mzgi3b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F5_mzgi3b.png" alt="composer create-project"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Require Laravel Breeze&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After installing Laravel, then change into the directory &lt;strong&gt;cd breeze/&lt;/strong&gt; and require Laravel Breeze with composer using the command below&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer require laravel/breeze --dev&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316055%2Flaravel%2520breeze%2F6_cg01aj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316055%2Flaravel%2520breeze%2F6_cg01aj.png" alt="require breeze"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Install Laravel Breeze&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan breeze:install&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316055%2Flaravel%2520breeze%2F9_wfr8sf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316055%2Flaravel%2520breeze%2F9_wfr8sf.png" alt="install breeze"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Install the JavaScript pacakges&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After installing Laravel Breeze, it will prompt you to run&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm install &amp;amp;&amp;amp; npm run dev&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Setup Database&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Open your &lt;strong&gt;.env&lt;/strong&gt; file that was created and you will see that the  name of the project has automatically be entered as the database name, you can change it to the name of the database you want to use, or you leave it and create a new database with the name&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F7_t52d9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F7_t52d9e.png" alt=".env"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 6: Run migration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After setting up our database and editing it in the &lt;strong&gt;.env&lt;/strong&gt; file, we need to run the migration, but before that, we need to set the default string length, if not, this will throw errors in the course of migrations.&lt;br&gt;
Go to &lt;strong&gt;app/Providers/AppServiceProvider.php&lt;/strong&gt; and add the schema for the default string length in the &lt;strong&gt;boot&lt;/strong&gt; method.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Schema::defaultstringLength(191);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;remember to call the schema class at the top&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;use Illuminate\Support\Facades\Schema;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

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

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultstringLength(191);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then run the migration&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan migrate&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605318242%2Flaravel%2520breeze%2F10_htkzu1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605318242%2Flaravel%2520breeze%2F10_htkzu1.png" alt="migrate"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 7: Add your email login details&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is so we can be able to reset our password and other email features&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F8_acbi66.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605316054%2Flaravel%2520breeze%2F8_acbi66.png" alt="email settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 8: Start the App&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan serve&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="http://127.0.0.1:8000/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605319431%2Flaravel%2520breeze%2F13_uepfir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605319431%2Flaravel%2520breeze%2F13_uepfir.png" alt="home page"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;a href="http://127.0.0.1:8000/register" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/register&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605319371%2Flaravel%2520breeze%2F10_pa1g14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605319371%2Flaravel%2520breeze%2F10_pa1g14.png" alt="register"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;a href="http://127.0.0.1:8000/dashboard" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/dashboard&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605319371%2Flaravel%2520breeze%2F12_fa61yz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605319371%2Flaravel%2520breeze%2F12_fa61yz.png" alt="dashboard"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;a href="http://127.0.0.1:8000/login" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/login&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605319371%2Flaravel%2520breeze%2F11_elo3bh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1605319371%2Flaravel%2520breeze%2F11_elo3bh.png" alt="dashboard"&gt;&lt;/a&gt;&lt;br&gt;
Now you have your basic laravel app with Auth setup.&lt;br&gt;
Follow me for more of my articles, you can leave comments, suggestions, and reactions.&lt;br&gt;
I am open to any vacancy as a PHP backend engineer, my strength is in the Laravel framework &lt;/p&gt;

&lt;p&gt;Watch the video on &lt;a href="https://youtu.be/0S15GNx_32U" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to create Recycle Bin with Soft Delete in Laravel 8 and 7</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Fri, 06 Nov 2020 23:01:05 +0000</pubDate>
      <link>https://forem.com/kingsconsult/how-to-create-recycle-bin-with-soft-delete-in-laravel-8-and-7-1ldo</link>
      <guid>https://forem.com/kingsconsult/how-to-create-recycle-bin-with-soft-delete-in-laravel-8-and-7-1ldo</guid>
      <description>&lt;p&gt;Hello guys, I want to treat some Laravel concepts about deleting, sometimes we may want to design our application so that even though the user deletes a data, it is not permanently deleted, it will still remain in the database but will not show up in the view. Laravel has provided this functionality out of the box for us called &lt;strong&gt;softDelete&lt;/strong&gt;, so I am going to illustrate how to delete data and view the deleted data and also how to restore the deleted data, and finally, how to permanently delete the data, I called this concept &lt;strong&gt;Recycle Bin&lt;/strong&gt;.&lt;br&gt;
We are going to be using the code from my previous article &lt;a href="https://dev.to/kingsconsult/laravel-8-crud-bi9"&gt;Laravel 8 CRUD App, A simple guide&lt;/a&gt;, the &lt;a href="https://github.com/Kingsconsult/laravel_8_crud" rel="noopener noreferrer"&gt;repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you prefer videos, you can watch the video from &lt;a href="https://www.youtube.com/watch?v=-ujO2t9mHPU" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Setup the app&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;git clone &lt;a href="https://github.com/Kingsconsult/laravel_8_crud.git" rel="noopener noreferrer"&gt;https://github.com/Kingsconsult/laravel_8_crud.git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;cd laravel_8_crud/&lt;/li&gt;
&lt;li&gt;composer install&lt;/li&gt;
&lt;li&gt;npm install&lt;/li&gt;
&lt;li&gt;cp .env.example .env&lt;/li&gt;
&lt;li&gt;php artisan key:generate&lt;/li&gt;
&lt;li&gt;Add your database config in the .env file (you can check my articles on how to achieve that)&lt;/li&gt;
&lt;li&gt;php artisan migrate&lt;/li&gt;
&lt;li&gt;php artisan serve (if the server opens up, &lt;a href="http://127.0.0.1:8000" rel="noopener noreferrer"&gt;http://127.0.0.1:8000&lt;/a&gt;,  then we are good to go)
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1600705305%2Flaravel%25208%2520modal%2F4_pp7r76.png" alt="localhost"&gt;
&lt;/li&gt;
&lt;li&gt;Navigate to &lt;a href="http://127.0.0.1:8000/projects" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/projects&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Add delete_at column to projects table&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In Laravel Soft Delete, data are not actually deleted from the database but a &lt;strong&gt;deleted_at&lt;/strong&gt; attribute is added to the data, so when we are querying data from the database, Eloquent looks for data with null &lt;strong&gt;deleted_at&lt;/strong&gt; value and give out, but when a data has non-null &lt;strong&gt;deleted_at&lt;/strong&gt; value, it treats it as a deleted data.&lt;br&gt;
So we need to add it and run our migration again.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604689251%2Flaravel%25208%2520recycle%2520bin%2F1_ybdh1n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604689251%2Flaravel%25208%2520recycle%2520bin%2F1_ybdh1n.png" alt="create migration file"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Add the delete_at column to the migration file&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Running the command in step 2 will create a migration file in &lt;strong&gt;database/migrations/&lt;/strong&gt;, edit the file and add &lt;strong&gt;$table-&amp;gt;softDeletes();&lt;/strong&gt; to the &lt;strong&gt;up()&lt;/strong&gt; function and also &lt;strong&gt;$table-&amp;gt;dropSoftDeletes();&lt;/strong&gt; to the &lt;strong&gt;down()&lt;/strong&gt; function, our migration file looks like this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604689251%2Flaravel%25208%2520recycle%2520bin%2F4_oznfem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604689251%2Flaravel%25208%2520recycle%2520bin%2F4_oznfem.png" alt="migration file"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Run migration again&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We need to run the migration again so that the new column will be added to the existing table&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan migrate&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604689251%2Flaravel%25208%2520recycle%2520bin%2F2_tb8u0a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604689251%2Flaravel%25208%2520recycle%2520bin%2F2_tb8u0a.png" alt="migration"&gt;&lt;/a&gt;&lt;br&gt;
Going to our database, you will see the new column created with values Null &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604689686%2Flaravel%25208%2520recycle%2520bin%2F3_wc23th.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604689686%2Flaravel%25208%2520recycle%2520bin%2F3_wc23th.png" alt="database"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Enable the softdelete trait on the model&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;app/Models/Project.php&lt;/strong&gt; and add the soft delete trait, this trait will tell the model to only add a date to the model that is deleted, but not deleting it permanently.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;use SoftDeletes;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Also, add the path of the trait at the top&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;use Illuminate\Database\Eloquent\SoftDeletes;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 6: Create the routes to get all deleted projects&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;routes/web.php&lt;/strong&gt; and add the route to get all deleted projects &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Route::get('projects/deletedprojects', [ProjectController::class, 'getDeleteProjects'])-&amp;gt;name('getDeleteProjects');&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 7: Create the Controller Method&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In our route above, we specified a &lt;strong&gt;getDeletedProjects&lt;/strong&gt; methods in the ProjectController class, so we create that method. Go to &lt;strong&gt;app/Http/Controllers/ProjectController.php&lt;/strong&gt; and add this method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public function getDeleteProjects() {
        $projects = Project::onlyTrashed()-&amp;gt;paginate(10);

        return view('projects.deletedprojects', compact('projects'))
            -&amp;gt;with('i', (request()-&amp;gt;input('page', 1) - 1) * 10);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the method above, we used an eloquent function &lt;strong&gt;onlyTrashed()&lt;/strong&gt;, this function only fetches the model with non-null deleted_at values, so it will fetch just the projects that are deleted. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 8: Create the blade file to view all deleted project&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;From our &lt;strong&gt;getDeletedProjects()&lt;/strong&gt; method above, we return to &lt;strong&gt;deletedprojects&lt;/strong&gt; view, so we need to create that, go to &lt;strong&gt;resources/views/projects/&lt;/strong&gt; and create the file &lt;strong&gt;deletedprojects.blade.php&lt;/strong&gt; and copy the index page and edit to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@extends('layouts.app')

@section('content')
    &amp;lt;div class="row"&amp;gt;
        &amp;lt;div class="col-lg-12 margin-tb"&amp;gt;
            &amp;lt;div class="pull-left"&amp;gt;
                &amp;lt;h2&amp;gt;Laravel 8 CRUD &amp;lt;/h2&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;div class="pull-left "&amp;gt;
        &amp;lt;a class="btn btn-success" href="{{ route('projects.index') }}" title="Back to Index"&amp;gt; &amp;lt;i class="fas fa-home"&amp;gt;&amp;lt;/i&amp;gt; &amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class=""&amp;gt;
        &amp;lt;div class="mx-auto pull-right"&amp;gt;
            &amp;lt;div class=""&amp;gt;
                &amp;lt;form action="{{ route('projects.index') }}" method="GET" role="search"&amp;gt;

                    &amp;lt;div class="input-group"&amp;gt;
                        &amp;lt;span class="input-group-btn mr-5 mt-1"&amp;gt;
                            &amp;lt;button class="btn btn-info" type="submit" title="Search projects"&amp;gt;
                                &amp;lt;span class="fas fa-search"&amp;gt;&amp;lt;/span&amp;gt;
                            &amp;lt;/button&amp;gt;
                        &amp;lt;/span&amp;gt;
                        &amp;lt;input type="text" class="form-control mr-2" name="term" placeholder="Search projects" id="term"&amp;gt;
                        &amp;lt;a href="{{ route('projects.index') }}" class=" mt-1"&amp;gt;
                            &amp;lt;span class="input-group-btn"&amp;gt;
                                &amp;lt;button class="btn btn-danger" type="button" title="Refresh page"&amp;gt;
                                    &amp;lt;span class="fas fa-sync-alt"&amp;gt;&amp;lt;/span&amp;gt;
                                &amp;lt;/button&amp;gt;
                            &amp;lt;/span&amp;gt;
                        &amp;lt;/a&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/form&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    @if ($message = Session::get('success'))
        &amp;lt;div class="alert alert-success"&amp;gt;
            &amp;lt;p&amp;gt;{{ $message }}&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    @endif

    &amp;lt;table class="table table-bordered table-responsive-lg"&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;th&amp;gt;No&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Introduction&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Location&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Cost&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Date Deleted&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Action&amp;lt;/th&amp;gt;
        &amp;lt;/tr&amp;gt;
        @foreach ($projects as $project)
            &amp;lt;tr&amp;gt;
                &amp;lt;td&amp;gt;{{ ++$i }}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;{{ $project-&amp;gt;name }}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;{{ $project-&amp;gt;introduction }}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;{{ $project-&amp;gt;location }}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;{{ $project-&amp;gt;cost }}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;{{ date_format($project-&amp;gt;deleted_at, 'jS M Y') }}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;
                    &amp;lt;a href="{{ route('restoreDeletedProjects', $project-&amp;gt;id) }}" title="restore project"&amp;gt;
                        &amp;lt;i class="fas fa-window-restore text-success  fa-lg"&amp;gt;&amp;lt;/i&amp;gt;
                    &amp;lt;/a&amp;gt;
                    &amp;lt;a href="{{ route('deletePermanently', $project-&amp;gt;id) }}" title="Permanently delete"&amp;gt;
                        &amp;lt;i class="fas fa-trash text-danger  fa-lg"&amp;gt;&amp;lt;/i&amp;gt;
                    &amp;lt;/a&amp;gt;
                &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
        @endforeach
    &amp;lt;/table&amp;gt;

    {!! $projects-&amp;gt;links() !!}


@endsection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the action column of a project from the code above, we added an icon to restore a deleted file, this will remove the value in the deleted_at in the table and we also added another icon to delete a project permanently, this will permanently delete the project from the database.&lt;br&gt;
Next, we need to create a function to restore the deleted project.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 9: Create Route to Restore Deleted Project&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Route::get('projects/deletedprojects/{id}', [ProjectController::class, 'restoreDeletedProjects'])-&amp;gt;name('restoreDeletedProjects');&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In our route, we also specify a controller method &lt;strong&gt;restoreDeletedProjects&lt;/strong&gt;, so we head to ProjectController and create the method&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 10: Create Controller Method to Restore Deleted Project&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Go to &lt;strong&gt;app/Http/Controllers/ProjectController.php&lt;/strong&gt; and add this method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public function restoreDeletedProjects($id) 
    {

        $project = Project::where('id', $id)-&amp;gt;withTrashed()-&amp;gt;first();

        $project-&amp;gt;restore();

        return redirect()-&amp;gt;route('projects.index')
            -&amp;gt;with('success', 'You successfully restored the project');
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 11: Create Route to permanently delete Project&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We need to also create a functionality, to permanently delete a project that we don't want to leave in the database, so let's create the route&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Route::get('projects/retoreprojects/{id}', [ProjectController::class, 'deletePermanently'])-&amp;gt;name('deletePermanently');&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 12: Create the Controller Method&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public function deletePermanently($id)
    {
        $project = Project::where('id', $id)-&amp;gt;withTrashed()-&amp;gt;first();

        $project-&amp;gt;forceDelete();

        return redirect()-&amp;gt;route('projects.index')
            -&amp;gt;with('success', 'You successfully deleted the project fromt the Recycle Bin');

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

&lt;/div&gt;



&lt;p&gt;That is all, let's test our work&lt;br&gt;
We created some projects, &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604701119%2Flaravel%25208%2520recycle%2520bin%2F5_ta4irg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604701119%2Flaravel%25208%2520recycle%2520bin%2F5_ta4irg.png" alt="index with all projects"&gt;&lt;/a&gt;&lt;br&gt;
We also added a recycle icon that will take us to the page that we display all deleted projects, then we deleted two of the projects and going to the recycle page&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604701078%2Flaravel%25208%2520recycle%2520bin%2F6_wd5glq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604701078%2Flaravel%25208%2520recycle%2520bin%2F6_wd5glq.png" alt="recycle page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604701119%2Flaravel%25208%2520recycle%2520bin%2F8_atus1m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604701119%2Flaravel%25208%2520recycle%2520bin%2F8_atus1m.png" alt="restored project"&gt;&lt;/a&gt;&lt;br&gt;
These are the projects we deleted from the index page, here we have two icons, one to restore deleted projects and the other to permanently delete the project from the database &lt;br&gt;
We restored a project, and it returns to the index, then finally, we deleted the other permanently &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604701119%2Flaravel%25208%2520recycle%2520bin%2F9_dcouj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604701119%2Flaravel%25208%2520recycle%2520bin%2F9_dcouj6.png" alt="permanently deleting a project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can get the complete code from the &lt;a href="https://github.com/Kingsconsult/laravel_8_recycle_bin" rel="noopener noreferrer"&gt;Github repo&lt;/a&gt;.&lt;br&gt;
Follow me for more of my articles, you can leave comments, suggestions, and reactions.&lt;br&gt;
I am open to any vacancy as a PHP backend engineer, my strength is in the Laravel framework &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to implement Delete Confirmation in Laravel 8, 7,6 with Modal</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Sun, 01 Nov 2020 05:16:26 +0000</pubDate>
      <link>https://forem.com/kingsconsult/how-to-implement-delete-confirmation-in-laravel-8-7-6-with-modal-29c5</link>
      <guid>https://forem.com/kingsconsult/how-to-implement-delete-confirmation-in-laravel-8-7-6-with-modal-29c5</guid>
      <description>&lt;p&gt;Hello devs, How are you doing? I am going to be showing you a little trick on how to implement delete confirmation using bootstrap modal.&lt;br&gt;
In designing an application, we need to take into consideration that the user might not be that careful in using our application or unconsciously be pressing something on their phone or with the mouse and can accidentally click the delete button, so we need to make sure that in terms of delicate activities like deleting a data, there should be some level of confirmation, there are many ways to achieve this, you can use alert or confirm in JavaScript with jQuery, but we are going to be using bootstrap, this way it will look better and give us more chances of customizing how the confirmation will look.&lt;br&gt;
Let's get into the business, We are going to be using the code from my previous article &lt;a href="https://dev.to/kingsconsult/laravel-8-crud-bi9"&gt;Laravel 8 CRUD App, A simple guide&lt;/a&gt;, the &lt;a href="https://github.com/Kingsconsult/laravel_8_crud" rel="noopener noreferrer"&gt;repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Setup the app&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;git clone &lt;a href="https://github.com/Kingsconsult/laravel_8_crud.git" rel="noopener noreferrer"&gt;https://github.com/Kingsconsult/laravel_8_crud.git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;cd laravel_8_crud/&lt;/li&gt;
&lt;li&gt;composer install&lt;/li&gt;
&lt;li&gt;npm install&lt;/li&gt;
&lt;li&gt;cp .env.example .env&lt;/li&gt;
&lt;li&gt;php artisan key:generate&lt;/li&gt;
&lt;li&gt;Add your database config in the .env file (you can check my articles on how to achieve that)&lt;/li&gt;
&lt;li&gt;php artisan migrate&lt;/li&gt;
&lt;li&gt;php artisan serve (if the server opens up, &lt;a href="http://127.0.0.1:8000" rel="noopener noreferrer"&gt;http://127.0.0.1:8000&lt;/a&gt;,  then we are good to go)
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1600705305%2Flaravel%25208%2520modal%2F4_pp7r76.png" alt="localhost"&gt;
&lt;/li&gt;
&lt;li&gt;Navigate to &lt;a href="http://127.0.0.1:8000/projects" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/projects&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: add delete route&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Laravel resources route provides us with seven (7) methods that handle the CRUD operation, which means we have the delete method called &lt;strong&gt;destroy&lt;/strong&gt; method already created. But we are going to add a new route called delete, what this route will do is redirect us to the modal that will execute the destroy method. So add the code below before the resource route for project&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Route::get('projects/delete/{id}', [ProjectController::class, 'delete'])-&amp;gt;name('delete');


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

&lt;/div&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604193837%2Flaravel%25208%2520delete%2520confirmation%2F1_ztgigx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604193837%2Flaravel%25208%2520delete%2520confirmation%2F1_ztgigx.png" alt="web route"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Create delete method&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In our route, we indicate that we have a delete method in the project controller, so we need to create that, go to &lt;strong&gt;app/Http/Controllers/ProjectController.php&lt;/strong&gt; and add the following method&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

public function delete($id)
{
    $project = Project::find($id);

    return view('projects.delete', compact('project'));
}


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

&lt;/div&gt;
&lt;p&gt;The delete function accepts an id, which is the id of the item we want to delete, and return the delete view in our projects directory along with the id of the item.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Create Delete view&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In our delete method, we return the delete view, so we need to create that, go to &lt;strong&gt;resources/views/projects/&lt;/strong&gt; and create a delete blade file &lt;strong&gt;delete.blade.php&lt;/strong&gt; and copy the code below and paste.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{{-- !-- Delete Warning Modal --&amp;gt;  --}}
&amp;lt;form action="{{ route('projects.destroy', $project-&amp;gt;id) }}" method="post"&amp;gt;
    &amp;lt;div class="modal-body"&amp;gt;
        @csrf
        @method('DELETE')
        &amp;lt;h5 class="text-center"&amp;gt;Are you sure you want to delete {{ $project-&amp;gt;name }} ?&amp;lt;/h5&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="modal-footer"&amp;gt;
        &amp;lt;button type="button" class="btn btn-secondary" data-dismiss="modal"&amp;gt;Cancel&amp;lt;/button&amp;gt;
        &amp;lt;button type="submit" class="btn btn-danger"&amp;gt;Yes, Delete Project&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/form&amp;gt;


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

&lt;/div&gt;
&lt;p&gt;From the code above, we need to pass an id to the destroy method, the id of the item to be deleted, we also customize the delete message, so that the user will be sure what to delete. &lt;br&gt;
The form will be the modal that will display for confirmation before deleting, the &lt;strong&gt;submit&lt;/strong&gt; button will be the button that will execute the deleting, while the button with type button will cancel the form which will not delete the item.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Edit the index.blade.php&lt;/strong&gt;
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@extends('layouts.app')

@section('content')

&amp;lt;div class="row"&amp;gt;
    &amp;lt;div class="col-lg-12 margin-tb"&amp;gt;
        &amp;lt;div class="pull-left"&amp;gt;
            &amp;lt;h2&amp;gt;Laravel 8 CRUD &amp;lt;/h2&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;div class="pull-left "&amp;gt;
    &amp;lt;a class="btn btn-success" href="{{ route('projects.create') }}" title="Create a project"&amp;gt; &amp;lt;i class="fas fa-plus-circle"&amp;gt;&amp;lt;/i&amp;gt;
    &amp;lt;/a&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div class="d-flex"&amp;gt;
    &amp;lt;div class="mx-auto"&amp;gt;

        &amp;lt;form action="{{ route('projects.index') }}" method="GET" role="search"&amp;gt;

            &amp;lt;div class="d-flex"&amp;gt;

                &amp;lt;button class="btn btn-info t" type="submit" title="Search projects"&amp;gt;
                    &amp;lt;span class="fas fa-search"&amp;gt;&amp;lt;/span&amp;gt;
                &amp;lt;/button&amp;gt;
                &amp;lt;input type="text" class="form-control mr-2" name="term" placeholder="Search projects" id="term"&amp;gt;
                &amp;lt;a href="{{ route('projects.index') }}" class=""&amp;gt;
                    &amp;lt;button class="btn btn-danger" type="button" title="Refresh page"&amp;gt;
                        &amp;lt;span class="fas fa-sync-alt"&amp;gt;&amp;lt;/span&amp;gt;
                    &amp;lt;/button&amp;gt;

                &amp;lt;/a&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

@if ($message = Session::get('success'))
&amp;lt;div class="alert alert-success"&amp;gt;
    &amp;lt;p&amp;gt;{{ $message }}&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
@endif

&amp;lt;table class="table table-bordered table-responsive table-hover"&amp;gt;
    &amp;lt;thead class="thead-dark"&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;th scope="col"&amp;gt;No&amp;lt;/th&amp;gt;
            &amp;lt;th scope="col"&amp;gt;Name&amp;lt;/th&amp;gt;
            &amp;lt;th scope="col"&amp;gt;Introduction&amp;lt;/th&amp;gt;
            &amp;lt;th scope="col"&amp;gt;Location&amp;lt;/th&amp;gt;
            &amp;lt;th scope="col"&amp;gt;Cost&amp;lt;/th&amp;gt;
            &amp;lt;th scope="col"&amp;gt;Date Created&amp;lt;/th&amp;gt;
            &amp;lt;th scope="col"&amp;gt;Action&amp;lt;/th&amp;gt;
        &amp;lt;/tr&amp;gt;
    &amp;lt;/thead&amp;gt;
    &amp;lt;tbody&amp;gt;
        @foreach ($projects as $project)
        &amp;lt;tr&amp;gt;
            &amp;lt;td scope="row"&amp;gt;{{ ++$i }}&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;{{ $project-&amp;gt;name }}&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;{{ $project-&amp;gt;introduction }}&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;{{ $project-&amp;gt;location }}&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;{{ $project-&amp;gt;cost }}&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;{{ date_format($project-&amp;gt;created_at, 'jS M Y') }}&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;

                &amp;lt;a href="{{ route('projects.show', $project-&amp;gt;id) }}" title="show"&amp;gt;
                    &amp;lt;i class="fas fa-eye text-success  fa-lg"&amp;gt;&amp;lt;/i&amp;gt;
                &amp;lt;/a&amp;gt;

                &amp;lt;a href="{{ route('projects.edit', $project-&amp;gt;id) }}"&amp;gt;
                    &amp;lt;i class="fas fa-edit  fa-lg"&amp;gt;&amp;lt;/i&amp;gt;

                &amp;lt;/a&amp;gt;
                &amp;lt;a data-toggle="modal" id="smallButton" data-target="#smallModal" data-attr="{{ route('delete', $project-&amp;gt;id) }}" title="Delete Project"&amp;gt;
                    &amp;lt;i class="fas fa-trash text-danger  fa-lg"&amp;gt;&amp;lt;/i&amp;gt;
                &amp;lt;/a&amp;gt;
            &amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
        @endforeach
    &amp;lt;/tbody&amp;gt;

&amp;lt;/table&amp;gt;

{!! $projects-&amp;gt;links() !!}

&amp;lt;!-- small modal --&amp;gt;
&amp;lt;div class="modal fade" id="smallModal" tabindex="-1" role="dialog" aria-labelledby="smallModalLabel" aria-hidden="true"&amp;gt;
    &amp;lt;div class="modal-dialog modal-sm" role="document"&amp;gt;
        &amp;lt;div class="modal-content"&amp;gt;
            &amp;lt;div class="modal-header"&amp;gt;
                &amp;lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&amp;gt;
                    &amp;lt;span aria-hidden="true"&amp;gt;&amp;amp;times;&amp;lt;/span&amp;gt;
                &amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="modal-body" id="smallBody"&amp;gt;
                &amp;lt;div&amp;gt;
                    &amp;lt;!-- the result to be displayed apply here --&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;script&amp;gt;
    // display a modal (small modal)
    $(document).on('click', '#smallButton', function(event) {
        event.preventDefault();
        let href = $(this).attr('data-attr');
        $.ajax({
            url: href
            , beforeSend: function() {
                $('#loader').show();
            },
            // return the result
            success: function(result) {
                $('#smallModal').modal("show");
                $('#smallBody').html(result).show();
            }
            , complete: function() {
                $('#loader').hide();
            }
            , error: function(jqXHR, testStatus, error) {
                console.log(error);
                alert("Page " + href + " cannot open. Error:" + error);
                $('#loader').hide();
            }
            , timeout: 8000
        })
    });

&amp;lt;/script&amp;gt;

@endsection


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

&lt;/div&gt;
&lt;p&gt;For the explanation of how I implement the modal functionality above, visit my previous article &lt;a href="https://dev.to/kingsconsult/how-to-create-modal-in-laravel-8-and-laravel-6-7-with-ajax-m25"&gt;How to create modal in Laravel 8 and Laravel 6/7 with AJax&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Edit the base layout of our app to add the jquery, ajax and bootstrap needed, go to &lt;strong&gt;resources/views/layouts/app.blade.php&lt;/strong&gt;, copy and paste the code below.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;App Name - @yield('title')&amp;lt;/title&amp;gt;

    &amp;lt;link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css"
        rel="stylesheet"&amp;gt;

    &amp;lt;!-- Font Awesome JS --&amp;gt;
    &amp;lt;script defer src="https://use.fontawesome.com/releases/v5.0.13/js/solid.js"
        integrity="sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ" crossorigin="anonymous"&amp;gt;
    &amp;lt;/script&amp;gt;
    &amp;lt;script defer src="https://use.fontawesome.com/releases/v5.0.13/js/fontawesome.js"
        integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"&amp;gt;
    &amp;lt;/script&amp;gt;

    &amp;lt;link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"&amp;gt;

    &amp;lt;link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet' type='text/css'&amp;gt;



  &amp;lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' type='text/javascript'&amp;gt;&amp;lt;/script&amp;gt;


    &amp;lt;style&amp;gt;
        .footer {
            position: fixed;
            left: 0;
            bottom: 0;
            width: 100%;
            background-color: #9C27B0;
            color: white;
            text-align: center;
        }

        body {
            background-color: #EDF7EF
        }

    &amp;lt;/style&amp;gt;

&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    @section('sidebar')

    @show

    &amp;lt;div class="container"&amp;gt;
        @yield('content')
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="text-center footer"&amp;gt;

        &amp;lt;h4&amp;gt;The writer needs a job&amp;lt;/h4&amp;gt;
        &amp;lt;h4&amp;gt;+234 806 605 6233&amp;lt;/h4&amp;gt;
        &amp;lt;h4&amp;gt;kingsconsult001@gmail.com&amp;lt;/h4&amp;gt;
        &amp;lt;h4&amp;gt;Github: www.github.com/kingsconsult&amp;lt;/h4&amp;gt;

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


&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;


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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;&lt;br&gt;
Restarting our server in case, it is not running and going to projects&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan serve&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="http://127.0.0.1:8000/projects" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/projects&lt;/a&gt; , create some projects to test&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604205530%2Flaravel%25208%2520delete%2520confirmation%2F2_fezjgz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604205530%2Flaravel%25208%2520delete%2520confirmation%2F2_fezjgz.png" alt="projects index"&gt;&lt;/a&gt;&lt;br&gt;
Click on the trash icon to delete a project&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604205531%2Flaravel%25208%2520delete%2520confirmation%2F3_tbzcvd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1604205531%2Flaravel%25208%2520delete%2520confirmation%2F3_tbzcvd.png" alt="delete modal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can get the complete code from the &lt;a href="https://github.com/Kingsconsult/laravel_8_delete_confirmation" rel="noopener noreferrer"&gt;Github repo&lt;/a&gt;.&lt;br&gt;
Follow me for more of my articles, you can leave comments, suggestions, and reactions.&lt;br&gt;
I am open to any vacancy as a PHP backend engineer, my strength is in the Laravel framework &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visit my other posts &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/kingsconsult" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F207008%2F6be60c51-19c9-46cf-bfd1-4370aec78d12.jpg" alt="kingsconsult"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kingsconsult/how-to-create-a-secure-crud-restful-api-in-laravel-8-and-7-using-laravel-passport-31fh" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How to Create a Secure CRUD RESTful API in Laravel 8 and 7 Using Laravel Passport&lt;/h2&gt;
      &lt;h3&gt;Kingsconsult ・ Oct 15 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#php&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#laravel&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/kingsconsult" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F207008%2F6be60c51-19c9-46cf-bfd1-4370aec78d12.jpg" alt="kingsconsult"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kingsconsult/how-to-consume-restful-apis-in-laravel-8-and-laravel-7-4gii" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How to consume RESTful APIs in Laravel 8 and Laravel 7&lt;/h2&gt;
      &lt;h3&gt;Kingsconsult ・ Oct 28 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#php&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#laravel&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>php</category>
      <category>laravel</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to consume RESTful APIs in Laravel 8 and Laravel 7</title>
      <dc:creator>Kingsconsult</dc:creator>
      <pubDate>Wed, 28 Oct 2020 03:50:55 +0000</pubDate>
      <link>https://forem.com/kingsconsult/how-to-consume-restful-apis-in-laravel-8-and-laravel-7-4gii</link>
      <guid>https://forem.com/kingsconsult/how-to-consume-restful-apis-in-laravel-8-and-laravel-7-4gii</guid>
      <description>&lt;p&gt;Today, I am going to show you how to consume RESTful APIs, in my previous post I discuss &lt;a href="https://dev.to/kingsconsult/how-to-create-a-secure-crud-restful-api-in-laravel-8-and-7-using-laravel-passport-31fh"&gt;How to Create a Secure CRUD RESTful API in Laravel 8 and 7 Using Laravel Passport&lt;/a&gt;, the article teaches you how to create a RESTful API and also securing the API with Passport, Laravel Passport is the official OAuth2 server for Laravel apps. It provides you with a full OAuth2 server implementation. &lt;br&gt;
But in this article, we are only going to be discussing how to consume external API. Why some APIs are authenticated which will require providing a token in order to access the API, others are not authenticated, which means you can access the API without a token.&lt;br&gt;
This article will show you how to implement the two instances. We are going to be using the code from my previous article &lt;a href="https://dev.to/kingsconsult/laravel-8-crud-bi9"&gt;Laravel 8 CRUD App, A simple guide&lt;/a&gt;, this is the &lt;a href="https://github.com/Kingsconsult/laravel_8_crud" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;  for the code snippets. &lt;/p&gt;

&lt;p&gt;Click on my &lt;a href="https://dev.to/kingsconsult"&gt;profile&lt;/a&gt; to follow me to get more updates.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Setup the app&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;git clone &lt;a href="https://github.com/Kingsconsult/laravel_8_crud.git" rel="noopener noreferrer"&gt;https://github.com/Kingsconsult/laravel_8_crud.git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;cd laravel_8_crud/&lt;/li&gt;
&lt;li&gt;composer install&lt;/li&gt;
&lt;li&gt;npm install&lt;/li&gt;
&lt;li&gt;cp .env.example .env&lt;/li&gt;
&lt;li&gt;php artisan key:generate&lt;/li&gt;
&lt;li&gt;Add your database config in the .env file (you can check my articles on how to achieve that)&lt;/li&gt;
&lt;li&gt;php artisan migrate&lt;/li&gt;
&lt;li&gt;php artisan serve (if the server opens up, &lt;a href="http://127.0.0.1:8000" rel="noopener noreferrer"&gt;http://127.0.0.1:8000&lt;/a&gt;,  then we are good to go)
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1600705305%2Flaravel%25208%2520modal%2F4_pp7r76.png" alt="localhost"&gt;
&lt;/li&gt;
&lt;li&gt;Navigate to &lt;a href="http://127.0.0.1:8000/projects" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/projects&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Make sure Guzzle package is installed&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;By default, Laravel automatically includes this Guzzle as a dependency when you install Laravel, check your composer.json, if it is one of the required dependency, if you did not see it, or you want to update&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer require guzzlehttp/guzzle&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Create routes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Modify the &lt;strong&gt;routes/web.php&lt;/strong&gt; file to this&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProjectController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::prefix('projects')-&amp;gt;group(function () {
    Route::get('apiwithoutkey', [ProjectController::class, 'apiWithoutKey'])-&amp;gt;name('apiWithoutKey');
    Route::get('apiwithkey', [ProjectController::class, 'apiWithKey'])-&amp;gt;name('apiWithKey');
});


Route::resource('projects', ProjectController::class);


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

&lt;/div&gt;
&lt;p&gt;We added two get routes, one for an API without key (unauthorized) and another with key (authorized).&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Create Controller methods&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In our routes, we indicate that we have two more routes, so we need to write the methods,  go to &lt;strong&gt;app/Http/Controller/ProjectController.php&lt;/strong&gt;, and add the following methods &lt;br&gt;
First, call the Guzzle class before the controller class, directly under the namespace&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;use GuzzleHttp\Client;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


    public function apiWithoutKey()
    {
        $client = new Client(); //GuzzleHttp\Client
        $url = "https://api.github.com/users/kingsconsult/repos";


        $response = $client-&amp;gt;request('GET', $url, [
            'verify'  =&amp;gt; false,
        ]);

        $responseBody = json_decode($response-&amp;gt;getBody());

        return view('projects.apiwithoutkey', compact('responseBody'));
    }

    public function apiWithKey()
    {
        $client = new Client();
        $url = "https://dev.to/api/articles/me/published";

        $params = [
            //If you have any Params Pass here
        ];

        $headers = [
            'api-key' =&amp;gt; 'k3Hy5qr73QhXrmHLXhpEh6CQ'
        ];

        $response = $client-&amp;gt;request('GET', $url, [
            // 'json' =&amp;gt; $params,
            'headers' =&amp;gt; $headers,
            'verify'  =&amp;gt; false,
        ]);

        $responseBody = json_decode($response-&amp;gt;getBody());

        return view('projects.apiwithkey', compact('responseBody'));
    }


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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I instantiate the client class from guzzle.&lt;/li&gt;
&lt;li&gt;I assign the API URL to a variable (I used GitHub API for my public repositories, this is a public API that fetches one's public GitHub repositories), this API does not require a token for authorization.&lt;/li&gt;
&lt;li&gt;I use the request method of the client, it accepts 3 parameters ($method, $url, $options), the $options is where we pass our token if the API requires one, also I passed another option, verify, to be false.&lt;/li&gt;
&lt;li&gt;Finally, I convert my response to a json format, so I can pass it to the view.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The second method is for an API that requires authorization, I used dev.to API, this API fetches all my published articles and also all the stats for each article, I passed the &lt;strong&gt;api key&lt;/strong&gt; to the options, I assigned it to a variable call headers. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Create the views&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;I created separate views for the two API&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;resources/views/projects/apiwithoutkey.blade.php&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@extends('layouts.app')

@section('content')

&amp;lt;style&amp;gt;


&amp;lt;/style&amp;gt;
&amp;lt;div class="row mb-3"&amp;gt;
    &amp;lt;div class="col-lg-12 margin-tb"&amp;gt;
        &amp;lt;div class="text-center"&amp;gt;
            &amp;lt;h2&amp;gt;Github Public Repository&amp;lt;/h2&amp;gt;
            &amp;lt;a class="btn btn-primary" href="{{ route('projects.index') }}" title="Go back"&amp;gt; &amp;lt;i class="fas fa-backward fa-2x"&amp;gt;&amp;lt;/i&amp;gt; &amp;lt;/a&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;



&amp;lt;div class="container-fluid mb-5" style="margin-bottom: 150px !important"&amp;gt;
    &amp;lt;div class="row mr-4"&amp;gt;
        @foreach ($responseBody as $response)

        &amp;lt;div class="col-xl-3 col-md-6 mb-4 hvr-grow "&amp;gt;
            &amp;lt;a href="{{ $response-&amp;gt;html_url }}" class="text-muted"&amp;gt;
                &amp;lt;div class="card shadow  py-0 rounded-lg "&amp;gt;
                    &amp;lt;div class="card-body py-2 px-2"&amp;gt;
                        &amp;lt;div class="row no-gutters align-items-center"&amp;gt;
                            &amp;lt;div class="col mr-2"&amp;gt;
                                &amp;lt;div class=" font-weight-bold mb-4 mt- 2 text-primary text-center text-uppercase mb-1"&amp;gt;
                                    {{ $response-&amp;gt;name }}
                                &amp;lt;/div&amp;gt;
                                &amp;lt;div class="h6 mb-0 text-gray-800 text-center"&amp;gt;{{ $response-&amp;gt;description }}
                                    @if ($response-&amp;gt;description == null)
                                    {{ $response-&amp;gt;name }}
                                    @endif
                                &amp;lt;/div&amp;gt;
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;

                        &amp;lt;div style="position: absolute; bottom: 0" class="mb-2"&amp;gt; &amp;lt;strong&amp;gt;
                                &amp;lt;hi&amp;gt;Language : {{ $response-&amp;gt;language }}
                            &amp;lt;/strong&amp;gt;&amp;lt;/hi&amp;gt;
                        &amp;lt;/div&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/a&amp;gt;
        &amp;lt;/div&amp;gt;
        @endforeach
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

@endsection


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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;resources/views/projects/apiwithkey.blade.php&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@extends('layouts.app')

@section('content')

&amp;lt;style&amp;gt;


&amp;lt;/style&amp;gt;
&amp;lt;div class="row mb-3"&amp;gt;
    &amp;lt;div class="col-lg-12 margin-tb"&amp;gt;
        &amp;lt;div class="text-center"&amp;gt;
            &amp;lt;h2&amp;gt;Dev.to Article stats&amp;lt;/h2&amp;gt;
            &amp;lt;a class="btn btn-primary" href="{{ route('projects.index') }}" title="Go back"&amp;gt; &amp;lt;i class="fas fa-backward fa-2x"&amp;gt;&amp;lt;/i&amp;gt; &amp;lt;/a&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;



&amp;lt;div class="container-fluid mb-5" style="margin-bottom: 150px !important"&amp;gt;
    &amp;lt;div class="row mr-4"&amp;gt;
        @foreach ($responseBody as $response)

        &amp;lt;div class="col-xl-3 col-md-6 mb-4 hvr-grow "&amp;gt;
            &amp;lt;div class="card shadow  py-0 rounded-lg "&amp;gt;
                &amp;lt;div class="card-body py-2"&amp;gt;
                    &amp;lt;div class="row no-gutters align-items-center"&amp;gt;
                        &amp;lt;div class="col mr-2"&amp;gt;
                            &amp;lt;a href="{{ $response-&amp;gt;url }}" class="text-muted"&amp;gt;
                                &amp;lt;div class=" font-weight-bold mb-2 mt-2 text-primary text-center text-uppercase mb-1"&amp;gt;
                                    {{ Str::limit($response-&amp;gt;title, 45) }}

                                &amp;lt;/div&amp;gt;
                            &amp;lt;/a&amp;gt;
                            &amp;lt;div class="h6 mb-0 text-gray-800 text-center"&amp;gt;
                                {{ Str::limit($response-&amp;gt;description, 100) }}
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;
                    &amp;lt;/div&amp;gt;
                    &amp;lt;div style="position: absolute; bottom: 0" class="mb-2"&amp;gt;
                        &amp;lt;hi&amp;gt;Page Views: &amp;lt;strong&amp;gt;{{ number_format($response-&amp;gt;page_views_count) }}&amp;lt;/strong&amp;gt;&amp;lt;/hi&amp;gt;
                        &amp;lt;hi class="ml-3"&amp;gt; Reactions: &amp;lt;strong&amp;gt;{{ $response-&amp;gt;positive_reactions_count }} &amp;lt;/strong&amp;gt;&amp;lt;/hi&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        @endforeach
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

@endsection


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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;&lt;br&gt;
Go to the index page of projects &lt;strong&gt;&lt;a href="http://127.0.0.1:8000/projects" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/projects&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1603855412%2Flaravel%25208%2520consume%2520api%2F2_at7edn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1603855412%2Flaravel%25208%2520consume%2520api%2F2_at7edn.png" alt="http://127.0.0.1:8000/projects"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="http://127.0.0.1:8000/projects/apiwithkey" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/projects/apiwithkey&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1603855412%2Flaravel%25208%2520consume%2520api%2F4_yvdsfo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1603855412%2Flaravel%25208%2520consume%2520api%2F4_yvdsfo.png" alt="API with key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="http://127.0.0.1:8000/projects/apiwithoutkey" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/projects/apiwithoutkey&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1603855412%2Flaravel%25208%2520consume%2520api%2F1_mkit1h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fkingsconsult%2Fimage%2Fupload%2Fv1603855412%2Flaravel%25208%2520consume%2520api%2F1_mkit1h.png" alt="API without key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can get the complete code from the &lt;a href="https://github.com/Kingsconsult/laravel_8_consume_api" rel="noopener noreferrer"&gt;repo&lt;/a&gt;.&lt;br&gt;
Follow me for more of my articles, you can leave comments, suggestions, and reactions&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/kingsconsult"&gt;click the link to view my profile and follow me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visit my other posts &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/kingsconsult" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F207008%2F6be60c51-19c9-46cf-bfd1-4370aec78d12.jpg" alt="kingsconsult"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kingsconsult/how-to-create-a-secure-crud-restful-api-in-laravel-8-and-7-using-laravel-passport-31fh" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How to Create a Secure CRUD RESTful API in Laravel 8 and 7 Using Laravel Passport&lt;/h2&gt;
      &lt;h3&gt;Kingsconsult ・ Oct 15 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#php&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#laravel&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/kingsconsult" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F207008%2F6be60c51-19c9-46cf-bfd1-4370aec78d12.jpg" alt="kingsconsult"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kingsconsult/how-to-get-the-entire-country-list-in-laravel-8-downwards-ahb" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Country list in laravel 8 and Laravel 7&lt;/h2&gt;
      &lt;h3&gt;Kingsconsult ・ Sep 26 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#countrylist&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#laravel&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#php&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>php</category>
      <category>laravel</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
