<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[TechTool India]]></title><description><![CDATA[Project Consulting, Web Apps, API, Mobile Application.
Laravel, PHP, Javascript, VueJs, React, ReactNative]]></description><link>https://techtoolindia.com</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1645257544376/RgBL5RNQb.png</url><title>TechTool India</title><link>https://techtoolindia.com</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 22:51:18 GMT</lastBuildDate><atom:link href="https://techtoolindia.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to insert Bulk Fake Data in Laravel 9 using Factory & Seeder.]]></title><description><![CDATA[In this post, I am going to explain about creating dummy data in the database by using Laravel Eloquent Factory and Seed The Database by using Database Seeder.
Eloquent Factory
Eloquent Factory is nothing but an image of a Model with fake data.
To cr...]]></description><link>https://techtoolindia.com/how-to-insert-bulk-fake-data-in-laravel-9-using-factory-seeder</link><guid isPermaLink="true">https://techtoolindia.com/how-to-insert-bulk-fake-data-in-laravel-9-using-factory-seeder</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Laravel 9]]></category><category><![CDATA[laravelframework]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Wed, 23 Nov 2022 07:29:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1669188145163/Z7bY9OjD7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this post, I am going to explain about creating dummy data in the database by using Laravel Eloquent Factory and Seed The Database by using Database Seeder.</p>
<h2 id="heading-eloquent-factory">Eloquent Factory</h2>
<p>Eloquent Factory is nothing but an image of a Model with fake data.</p>
<p>To create a model factory you have to run the command below.</p>
<pre><code class="lang-php">php artisan make:factory UserFactory --model=User
</code></pre>
<p>This will generate the file in database/factory/UserFactory.php</p>
<p>Now let's add fake data for each column.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">Database</span>\<span class="hljs-title">Factories</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Str</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Hash</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Factories</span>\<span class="hljs-title">Factory</span>;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@extends</span> \Illuminate\Database\Eloquent\Factories\Factory&lt;\App\Models\User&gt;
 */</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserFactory</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Factory</span>
</span>{
    <span class="hljs-comment">/**
     * Define the model's default state.
     *
     * <span class="hljs-doctag">@return</span> array&lt;string, mixed&gt;
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">definition</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">"name"</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;faker-&gt;name(),
            <span class="hljs-string">"email"</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;faker-&gt;unique()-&gt;safeEmail(),
            <span class="hljs-string">"username"</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;faker-&gt;unique()-&gt;userName(),
            <span class="hljs-string">"mobile_no"</span> =&gt; <span class="hljs-keyword">$this</span>-&gt;faker-&gt;phoneNumber(),
            <span class="hljs-string">"password"</span> =&gt; Hash::make(<span class="hljs-string">"Password"</span>),
            <span class="hljs-string">"email_verified_at"</span> =&gt; now(),
            <span class="hljs-string">"remember_token"</span> =&gt; Str::random(<span class="hljs-number">10</span>)
        ];
    }
}
</code></pre>
<p>Now to run the factory you can use Laravel Tinker.</p>
<p>In the terminal, you can run the command below to enable Laravel Tinker.</p>
<pre><code class="lang-php">php artisan tinker
</code></pre>
<p>Now run the factory using the model to generate a single record with fake data.</p>
<pre><code class="lang-php">App\Models\User::factory()-&gt;create();
</code></pre>
<p>To generate more than one record you have to specify the <code>count</code> for records.</p>
<pre><code class="lang-php">App\Models\User::factory()-&gt;count(<span class="hljs-number">10</span>)-&gt;create();
</code></pre>
<h2 id="heading-db-seeder">DB Seeder</h2>
<p>To make a seeder For UserTableSeeder by running the command below.</p>
<pre><code class="lang-php">php artisan make:seed UserTableSeeder
</code></pre>
<p>This command generate a file in <code>database/seeders/UserTableSeeder.php</code></p>
<p>Next Update the run function of the seeder file.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">Database</span>\<span class="hljs-title">Seeders</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Seeder</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Seeds</span>\<span class="hljs-title">WithoutModelEvents</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserTableSeeder</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Seeder</span>
</span>{
    <span class="hljs-comment">/**
     * Run the database seeds.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">run</span>(<span class="hljs-params"></span>)
    </span>{
        User::factory()-&gt;count(<span class="hljs-number">1000</span>)-&gt;create();
    }
}
</code></pre>
<p>Now Run the command below to seed the data,</p>
<pre><code class="lang-php">php artisan db:seed --<span class="hljs-class"><span class="hljs-keyword">class</span>=<span class="hljs-title">UserTableSeeder</span></span>
</code></pre>
<p>You can watch the explanation video for more clarity.</p>
<h3 id="heading-complete-video-tutorial-on-youtube">Complete Video Tutorial on YouTube.</h3>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/dROeStI4uvI

If you face any issues while implementing, please comment with your query.

Thank You for Reading

Reach Out To me.
[Twitter">https://youtu.be/dROeStI4uvI

If you face any issues while implementing, please comment with your query.

Thank You for Reading

Reach Out To me.
[Twitter</a></div>
<p>(https://twitter.com/techtoolindia)
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[Laravel Passwordless Login with Magic Link]]></title><description><![CDATA[In this post, I will explain about login in with Magic Link in LARAVEL 9.
After Installing Laravel and Laravel Authentication open code project in a code editor & follow the steps below.
Step -1
To make passwordless login with Magic Link, we are goin...]]></description><link>https://techtoolindia.com/laravel-passwordless-login-with-magic-link</link><guid isPermaLink="true">https://techtoolindia.com/laravel-passwordless-login-with-magic-link</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Laravel 9]]></category><category><![CDATA[Laraveldevelopment ]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Thu, 22 Sep 2022 07:35:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1663831813822/xtfgtdDR_.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this post, I will explain about login in with Magic Link in LARAVEL 9.</p>
<p>After <a target="_blank" href="https://dev.to/shanisingh03/how-to-install-laravel-9-25c4">Installing Laravel</a> and <a target="_blank" href="https://dev.to/shanisingh03/how-to-make-login-registration-in-laravel-9-1p2n">Laravel Authentication</a> open code project in a code editor &amp; follow the steps below.</p>
<h2 id="heading-step-1">Step -1</h2>
<p>To make passwordless login with Magic Link, we are going to use <a target="_blank" href="https://github.com/grosv/laravel-passwordless-login">Laravel Password Less</a> Package.</p>
<p>All you need to do is run the composer command.</p>
<pre><code class="lang-php">composer <span class="hljs-keyword">require</span> grosv/laravel-passwordless-login
</code></pre>
<h2 id="heading-step-2">Step - 2</h2>
<p>Make Changes in the login view file, open <code>resources/views/auth/login.blade.php</code> and update the code below.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.app'</span>)

@section(<span class="hljs-string">'content'</span>)
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;</span>{{ __(<span class="hljs-string">'Login'</span>) }}&lt;/div&gt;

                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">body</span>"&gt;
                    &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">POST</span>" <span class="hljs-title">action</span>="</span>{{ route(<span class="hljs-string">'login'</span>) }}<span class="hljs-string">"&gt;
                        @csrf

                        @if (session('message'))
                            &lt;div class="</span>alert alert-info<span class="hljs-string">"&gt;{{ session('message') }}&lt;/div&gt;
                        @endif

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>username<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Username') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>username<span class="hljs-string">" type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'username'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>username<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'username'</span>) }}<span class="hljs-string">" required autocomplete="</span>username<span class="hljs-string">" autofocus&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>password<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Password') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>password<span class="hljs-string">" type="</span>password<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'password'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>password<span class="hljs-string">"  autocomplete="</span>current-password<span class="hljs-string">"&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-6</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                &lt;div class="</span>form-check<span class="hljs-string">"&gt;
                                    &lt;input class="</span>form-check-input<span class="hljs-string">" type="</span>checkbox<span class="hljs-string">" name="</span>remember<span class="hljs-string">" id="</span>remember<span class="hljs-string">" {{ old('remember') ? 'checked' : '' }}&gt;

                                    &lt;label class="</span>form-check-label<span class="hljs-string">" for="</span>remember<span class="hljs-string">"&gt;
                                        {{ __('Remember Me') }}
                                    &lt;/label&gt;
                                &lt;/div&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;

                        &lt;div class="</span>row mb<span class="hljs-number">-0</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-8</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                &lt;button type="</span>submit<span class="hljs-string">" name="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">" value="</span>login<span class="hljs-string">"&gt;
                                    {{ __('Login') }}
                                &lt;/button&gt;

                                or

                                &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string">" name="</span>submit<span class="hljs-string">" value="</span>magic-link<span class="hljs-string">"&gt;
                                    {{ __('Send Magic Link') }}
                                &lt;/button&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;

                        &lt;div class="</span>row mb<span class="hljs-number">-0</span> mt<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-8</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                @if (Route::has('password.request'))
                                    &lt;a class="</span>btn btn-link<span class="hljs-string">" href="</span>{{ route(<span class="hljs-string">'password.request'</span>) }}<span class="hljs-string">"&gt;
                                        {{ __('Forgot Your Password?') }}
                                    &lt;/a&gt;
                                @endif

                                &lt;a class="</span>btn btn-link<span class="hljs-string">" href="</span>{{ route(<span class="hljs-string">'otp.login'</span>) }}<span class="hljs-string">"&gt;
                                    {{ __('Login With OTP.') }}
                                &lt;/a&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection</span>
</code></pre>
<h2 id="heading-step-3">Step - 3</h2>
<p>Update the <code>app/Http/Controllers/Auth/LoginControlller.php</code> and add the login &amp; Login with Magic Link Function.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Auth</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Controller</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Notifications</span>\<span class="hljs-title">SendMagicLinkNotification</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Providers</span>\<span class="hljs-title">RouteServiceProvider</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Foundation</span>\<span class="hljs-title">Auth</span>\<span class="hljs-title">AuthenticatesUsers</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LoginController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">/*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */</span>

    <span class="hljs-keyword">use</span> <span class="hljs-title">AuthenticatesUsers</span>;

    <span class="hljs-comment">/**
     * Where to redirect users after login.
     *
     * <span class="hljs-doctag">@var</span> string
     */</span>
    <span class="hljs-keyword">protected</span> $redirectTo = RouteServiceProvider::HOME;

    <span class="hljs-comment">/**
     * Create a new controller instance.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;middleware(<span class="hljs-string">'guest'</span>)-&gt;except(<span class="hljs-string">'logout'</span>);
    }

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

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">login</span>(<span class="hljs-params">Request $request</span>)
    </span>{


        <span class="hljs-keyword">if</span>($request-&gt;input(<span class="hljs-string">'submit'</span>) == <span class="hljs-string">'magic-link'</span>){
            $user = <span class="hljs-keyword">$this</span>-&gt;loginViaMagicLink($request);

            <span class="hljs-keyword">if</span>(!$user){
                <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'login'</span>)
                -&gt;withErrors([<span class="hljs-string">'username'</span> =&gt; <span class="hljs-string">'User with this username does not exist.'</span>])
                -&gt;withInput();
            }

            <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'login'</span>)
            -&gt;withMessage(<span class="hljs-string">'Magic Link Sent to the registered email ID.'</span>);
        }

        <span class="hljs-keyword">$this</span>-&gt;validateLogin($request);

        <span class="hljs-comment">// If the class is using the ThrottlesLogins trait, we can automatically throttle</span>
        <span class="hljs-comment">// the login attempts for this application. We'll key this by the username and</span>
        <span class="hljs-comment">// the IP address of the client making these requests into this application.</span>
        <span class="hljs-keyword">if</span> (method_exists(<span class="hljs-keyword">$this</span>, <span class="hljs-string">'hasTooManyLoginAttempts'</span>) &amp;&amp;
            <span class="hljs-keyword">$this</span>-&gt;hasTooManyLoginAttempts($request)) {
            <span class="hljs-keyword">$this</span>-&gt;fireLockoutEvent($request);

            <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;sendLockoutResponse($request);
        }

        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">$this</span>-&gt;attemptLogin($request)) {
            <span class="hljs-keyword">if</span> ($request-&gt;hasSession()) {
                $request-&gt;session()-&gt;put(<span class="hljs-string">'auth.password_confirmed_at'</span>, time());
            }

            <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;sendLoginResponse($request);
        }

        <span class="hljs-comment">// If the login attempt was unsuccessful we will increment the number of attempts</span>
        <span class="hljs-comment">// to login and redirect the user back to the login form. Of course, when this</span>
        <span class="hljs-comment">// user surpasses their maximum number of attempts they will get locked out.</span>
        <span class="hljs-keyword">$this</span>-&gt;incrementLoginAttempts($request);

        <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;sendFailedLoginResponse($request);
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">loginViaMagicLink</span>(<span class="hljs-params">Request $request</span>)
    </span>{
        $user = User::where(<span class="hljs-string">'username'</span>, $request-&gt;input(<span class="hljs-string">'username'</span>))-&gt;first();

        <span class="hljs-keyword">if</span> ($user) {
            $user-&gt;notify(<span class="hljs-keyword">new</span> SendMagicLinkNotification());
        }

        <span class="hljs-keyword">return</span> $user;
    }
}
</code></pre>
<h2 id="heading-step-4">Step - 4</h2>
<p>Create notification to send a magic link on registered email.</p>
<pre><code class="lang-php">php artisan make:notification SendMagicLinkNotification
</code></pre>
<p>After creating the notification open it from <code>app/Notifications</code> and update the code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

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

<span class="hljs-keyword">use</span> <span class="hljs-title">Grosv</span>\<span class="hljs-title">LaravelPasswordlessLogin</span>\<span class="hljs-title">LoginUrl</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Bus</span>\<span class="hljs-title">Queueable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Contracts</span>\<span class="hljs-title">Queue</span>\<span class="hljs-title">ShouldQueue</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Notifications</span>\<span class="hljs-title">Messages</span>\<span class="hljs-title">MailMessage</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Notifications</span>\<span class="hljs-title">Notification</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SendMagicLinkNotification</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Notification</span>
</span>{
    <span class="hljs-keyword">use</span> <span class="hljs-title">Queueable</span>;

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

    <span class="hljs-comment">/**
     * Get the notification's delivery channels.
     *
     * <span class="hljs-doctag">@param</span>  mixed  $notifiable
     * <span class="hljs-doctag">@return</span> array
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">via</span>(<span class="hljs-params">$notifiable</span>)
    </span>{
        <span class="hljs-keyword">return</span> [<span class="hljs-string">'mail'</span>];
    }

    <span class="hljs-comment">/**
     * Get the mail representation of the notification.
     *
     * <span class="hljs-doctag">@param</span>  mixed  $notifiable
     * <span class="hljs-doctag">@return</span> \Illuminate\Notifications\Messages\MailMessage
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">toMail</span>(<span class="hljs-params">$notifiable</span>)
    </span>{

        $generator = <span class="hljs-keyword">new</span> LoginUrl($notifiable);
        $generator-&gt;setRedirectUrl(<span class="hljs-string">'/home'</span>);
        $url = $generator-&gt;generate();

        <span class="hljs-keyword">return</span> (<span class="hljs-keyword">new</span> MailMessage)
                    -&gt;subject(<span class="hljs-string">'Your Login Magic Link!'</span>)
                    -&gt;line(<span class="hljs-string">'Click this link to log in!'</span>)
                    -&gt;action(<span class="hljs-string">'Login'</span>, $url)
                    -&gt;line(<span class="hljs-string">'Thank you for using our application!'</span>);
    }

    <span class="hljs-comment">/**
     * Get the array representation of the notification.
     *
     * <span class="hljs-doctag">@param</span>  mixed  $notifiable
     * <span class="hljs-doctag">@return</span> array
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">toArray</span>(<span class="hljs-params">$notifiable</span>)
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-comment">//</span>
        ];
    }
}
</code></pre>
<p>That's it now you visit on the login page and you will see the magic link button on the login page.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/min9bktz43xy1bnt0sex.png" alt="Login" /></p>
<p>After you hit send the magic link you are going to get an email.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6j6y9cxpsvpj7luf5p2r.png" alt="Email" /></p>
<p>I hope this will help login with <code>MAGIC LINK</code> in LARAVEL 9.</p>
<h3 id="heading-complete-video-tutorial-on-youtube">Complete Video Tutorial on YouTube.</h3>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/hsSyS2VcLtM">https://youtu.be/hsSyS2VcLtM</a></div>
<p>If you face any issues while implementing, please comment with your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[Laravel Login with OTP]]></title><description><![CDATA[In this post, I am going to explain about login with OTP in LARAVEL 9.
After Installing Laravel and Laravel Authentication open code project in a code editor & follow the steps below.
Step - 1
Add Mobile Number in users table
To add a column, create ...]]></description><link>https://techtoolindia.com/laravel-login-with-otp</link><guid isPermaLink="true">https://techtoolindia.com/laravel-login-with-otp</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Laravel 9]]></category><category><![CDATA[laravel9]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Sat, 20 Aug 2022 07:22:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1660977776188/io2Q7KwnM.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this post, I am going to explain about login with OTP in LARAVEL 9.</p>
<p>After <a target="_blank" href="https://dev.to/shanisingh03/how-to-install-laravel-9-25c4">Installing Laravel</a> and <a target="_blank" href="https://dev.to/shanisingh03/how-to-make-login-registration-in-laravel-9-1p2n">Laravel Authentication</a> open code project in a code editor &amp; follow the steps below.</p>
<h2 id="heading-step-1">Step - 1</h2>
<h3 id="heading-add-mobile-number-in-users-table">Add Mobile Number in <code>users</code> table</h3>
<p>To add a column, create a Migration by running the command below.</p>
<pre><code class="lang-php">php artisan make:migration add_mobile_no_in_users_table
</code></pre>
<p>The Command will generate a file in <code>database/migrations</code> folder, open the migration file and update the code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Migrations</span>\<span class="hljs-title">Migration</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Schema</span>\<span class="hljs-title">Blueprint</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Schema</span>;

<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Migration</span>
</span>{
    <span class="hljs-comment">/**
     * Run the migrations.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)
    </span>{
        Schema::table(<span class="hljs-string">'users'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) </span>{
            $table-&gt;string(<span class="hljs-string">'mobile_no'</span>)-&gt;nullable()-&gt;after(<span class="hljs-string">'username'</span>);
        });
    }

    <span class="hljs-comment">/**
     * Reverse the migrations.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">down</span>(<span class="hljs-params"></span>)
    </span>{
        Schema::table(<span class="hljs-string">'users'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) </span>{
            $table-&gt;dropColumn(<span class="hljs-string">'mobile_no'</span>);
        });
    }
};
</code></pre>
<p>Now run the migration by command, it will add the mobile number in users table.</p>
<pre><code class="lang-php">php artisan migrate
</code></pre>
<p>Now Update the <code>app/Http/Controllers/Auth/RegisterController.php</code> to register a user with a mobile Number.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Auth</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Controller</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Providers</span>\<span class="hljs-title">RouteServiceProvider</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Foundation</span>\<span class="hljs-title">Auth</span>\<span class="hljs-title">RegistersUsers</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Hash</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Validator</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RegisterController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{

    <span class="hljs-keyword">use</span> <span class="hljs-title">RegistersUsers</span>;

    <span class="hljs-comment">/**
     * Where to redirect users after registration.
     *
     * <span class="hljs-doctag">@var</span> string
     */</span>
    <span class="hljs-keyword">protected</span> $redirectTo = RouteServiceProvider::HOME;

    <span class="hljs-comment">/**
     * Create a new controller instance.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;middleware(<span class="hljs-string">'guest'</span>);
    }

    <span class="hljs-comment">/**
     * Get a validator for an incoming registration request.
     *
     * <span class="hljs-doctag">@param</span>  array  $data
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Validation\Validator
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">validator</span>(<span class="hljs-params"><span class="hljs-keyword">array</span> $data</span>)
    </span>{
        <span class="hljs-keyword">return</span> Validator::make($data, [
            <span class="hljs-string">'name'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>],
            <span class="hljs-string">'username'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>],
            <span class="hljs-string">'mobile_no'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'number'</span>, <span class="hljs-string">'max:10'</span>],
            <span class="hljs-string">'email'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'email'</span>, <span class="hljs-string">'max:255'</span>, <span class="hljs-string">'unique:users'</span>],
            <span class="hljs-string">'password'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'min:8'</span>, <span class="hljs-string">'confirmed'</span>],
        ]);
    }

    <span class="hljs-comment">/**
     * Create a new user instance after a valid registration.
     *
     * <span class="hljs-doctag">@param</span>  array  $data
     * <span class="hljs-doctag">@return</span> \App\Models\User
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">create</span>(<span class="hljs-params"><span class="hljs-keyword">array</span> $data</span>)
    </span>{
        <span class="hljs-keyword">return</span> User::create([
            <span class="hljs-string">'name'</span> =&gt; $data[<span class="hljs-string">'name'</span>],
            <span class="hljs-string">'username'</span> =&gt; $data[<span class="hljs-string">'username'</span>],
            <span class="hljs-string">'mobile_no'</span> =&gt; $data[<span class="hljs-string">'mobile_no'</span>],
            <span class="hljs-string">'email'</span> =&gt; $data[<span class="hljs-string">'email'</span>],
            <span class="hljs-string">'password'</span> =&gt; Hash::make($data[<span class="hljs-string">'password'</span>]),
        ]);
    }
}
</code></pre>
<p>Next, update the 'resources/views/auth/register.blade.php' and update the code below.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.app'</span>)

@section(<span class="hljs-string">'content'</span>)
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;</span>{{ __(<span class="hljs-string">'Register'</span>) }}&lt;/div&gt;

                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">body</span>"&gt;
                    &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">POST</span>" <span class="hljs-title">action</span>="</span>{{ route(<span class="hljs-string">'register'</span>) }}<span class="hljs-string">"&gt;
                        @csrf

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>name<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Name') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>name<span class="hljs-string">" type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'name'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>name<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'name'</span>) }}<span class="hljs-string">" required autocomplete="</span>name<span class="hljs-string">" autofocus&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>username<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Username') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>username<span class="hljs-string">" type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'username'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>username<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'username'</span>) }}<span class="hljs-string">" required autocomplete="</span>username<span class="hljs-string">" autofocus&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>mobile_no<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Mobile No') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>mobile_no<span class="hljs-string">" type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'mobile_no'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>mobile_no<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'mobile_no'</span>) }}<span class="hljs-string">" required autocomplete="</span>mobile_no<span class="hljs-string">" autofocus&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>email<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Email Address') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>email<span class="hljs-string">" type="</span>email<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'email'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>email<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'email'</span>) }}<span class="hljs-string">" required autocomplete="</span>email<span class="hljs-string">"&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>password<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Password') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>password<span class="hljs-string">" type="</span>password<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'password'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>password<span class="hljs-string">" required autocomplete="</span><span class="hljs-keyword">new</span>-password<span class="hljs-string">"&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>password-confirm<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Confirm Password') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>password-confirm<span class="hljs-string">" type="</span>password<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" name="</span>password_confirmation<span class="hljs-string">" required autocomplete="</span><span class="hljs-keyword">new</span>-password<span class="hljs-string">"&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;

                        &lt;div class="</span>row mb<span class="hljs-number">-0</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-6</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">"&gt;
                                    {{ __('Register') }}
                                &lt;/button&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection</span>
</code></pre>
<p>The Register form will look like this.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/phb7e89a0p9nkekowyio.png" alt="Register" /></p>
<h2 id="heading-step-2">Step - 2</h2>
<p>Create VerificationCode Model with Migration by running the Command below.</p>
<pre><code class="lang-php">php artisan make:model VerificationCode -m
</code></pre>
<p>This command will create a VerificationCode model in <code>app/models</code> folder and a migration in <code>database/migrations</code>.</p>
<p>Let's open the VerificationCode Model from <code>app/Models/VerificationCode.php</code> &amp; update with code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

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

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Factories</span>\<span class="hljs-title">HasFactory</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">VerificationCode</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span>
</span>{
    <span class="hljs-keyword">use</span> <span class="hljs-title">HasFactory</span>;

    <span class="hljs-keyword">protected</span> $fillable = [<span class="hljs-string">'user_id'</span>, <span class="hljs-string">'otp'</span>, <span class="hljs-string">'expire_at'</span>];
}
</code></pre>
<p>Now update migration of <code>verification_codes</code> table, open file from <code>database/migrations</code> and update the code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Migrations</span>\<span class="hljs-title">Migration</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Schema</span>\<span class="hljs-title">Blueprint</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Schema</span>;

<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Migration</span>
</span>{
    <span class="hljs-comment">/**
     * Run the migrations.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)
    </span>{
        Schema::create(<span class="hljs-string">'verification_codes'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) </span>{
            $table-&gt;id();
            $table-&gt;bigInteger(<span class="hljs-string">'user_id'</span>);
            $table-&gt;string(<span class="hljs-string">'otp'</span>);
            $table-&gt;timestamp(<span class="hljs-string">'expire_at'</span>)-&gt;nullable();
            $table-&gt;timestamps();
        });
    }

    <span class="hljs-comment">/**
     * Reverse the migrations.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">down</span>(<span class="hljs-params"></span>)
    </span>{
        Schema::dropIfExists(<span class="hljs-string">'verification_codes'</span>);
    }
};
</code></pre>
<p>Next, run the migration to create <code>verification_codes</code> table.</p>
<pre><code class="lang-php">php artisan migrate
</code></pre>
<h2 id="heading-step-3">Step - 3</h2>
<p>Create AuthOtpController by running the command</p>
<pre><code class="lang-php">php artisan make:controller AuthOtpController
</code></pre>
<p>This controller will handle all the operation related to Authentication using OTP.
Open the controller from <code>app/Http/Controllers/AuthOtpController.php</code> &amp; Update the controller by the code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Carbon</span>\<span class="hljs-title">Carbon</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">VerificationCode</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Auth</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AuthOtpController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">// Return View of OTP Login Page</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">login</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">'auth.otp-login'</span>);
    }

    <span class="hljs-comment">// Generate OTP</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">generate</span>(<span class="hljs-params">Request $request</span>)
    </span>{
        <span class="hljs-comment"># Validate Data</span>
        $request-&gt;validate([
            <span class="hljs-string">'mobile_no'</span> =&gt; <span class="hljs-string">'required|exists:users,mobile_no'</span>
        ]);

        <span class="hljs-comment"># Generate An OTP</span>
        $verificationCode = <span class="hljs-keyword">$this</span>-&gt;generateOtp($request-&gt;mobile_no);

        $message = <span class="hljs-string">"Your OTP To Login is - "</span>.$verificationCode-&gt;otp;
        <span class="hljs-comment"># Return With OTP </span>

        <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'otp.verification'</span>, [<span class="hljs-string">'user_id'</span> =&gt; $verificationCode-&gt;user_id])-&gt;with(<span class="hljs-string">'success'</span>,  $message); 
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">generateOtp</span>(<span class="hljs-params">$mobile_no</span>)
    </span>{
        $user = User::where(<span class="hljs-string">'mobile_no'</span>, $mobile_no)-&gt;first();

        <span class="hljs-comment"># User Does not Have Any Existing OTP</span>
        $verificationCode = VerificationCode::where(<span class="hljs-string">'user_id'</span>, $user-&gt;id)-&gt;latest()-&gt;first();

        $now = Carbon::now();

        <span class="hljs-keyword">if</span>($verificationCode &amp;&amp; $now-&gt;isBefore($verificationCode-&gt;expire_at)){
            <span class="hljs-keyword">return</span> $verificationCode;
        }

        <span class="hljs-comment">// Create a New OTP</span>
        <span class="hljs-keyword">return</span> VerificationCode::create([
            <span class="hljs-string">'user_id'</span> =&gt; $user-&gt;id,
            <span class="hljs-string">'otp'</span> =&gt; rand(<span class="hljs-number">123456</span>, <span class="hljs-number">999999</span>),
            <span class="hljs-string">'expire_at'</span> =&gt; Carbon::now()-&gt;addMinutes(<span class="hljs-number">10</span>)
        ]);
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">verification</span>(<span class="hljs-params">$user_id</span>)
    </span>{
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">'auth.otp-verification'</span>)-&gt;with([
            <span class="hljs-string">'user_id'</span> =&gt; $user_id
        ]);
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">loginWithOtp</span>(<span class="hljs-params">Request $request</span>)
    </span>{
        <span class="hljs-comment">#Validation</span>
        $request-&gt;validate([
            <span class="hljs-string">'user_id'</span> =&gt; <span class="hljs-string">'required|exists:users,id'</span>,
            <span class="hljs-string">'otp'</span> =&gt; <span class="hljs-string">'required'</span>
        ]);

        <span class="hljs-comment">#Validation Logic</span>
        $verificationCode   = VerificationCode::where(<span class="hljs-string">'user_id'</span>, $request-&gt;user_id)-&gt;where(<span class="hljs-string">'otp'</span>, $request-&gt;otp)-&gt;first();

        $now = Carbon::now();
        <span class="hljs-keyword">if</span> (!$verificationCode) {
            <span class="hljs-keyword">return</span> redirect()-&gt;back()-&gt;with(<span class="hljs-string">'error'</span>, <span class="hljs-string">'Your OTP is not correct'</span>);
        }<span class="hljs-keyword">elseif</span>($verificationCode &amp;&amp; $now-&gt;isAfter($verificationCode-&gt;expire_at)){
            <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'otp.login'</span>)-&gt;with(<span class="hljs-string">'error'</span>, <span class="hljs-string">'Your OTP has been expired'</span>);
        }

        $user = User::whereId($request-&gt;user_id)-&gt;first();

        <span class="hljs-keyword">if</span>($user){
            <span class="hljs-comment">// Expire The OTP</span>
            $verificationCode-&gt;update([
                <span class="hljs-string">'expire_at'</span> =&gt; Carbon::now()
            ]);

            Auth::login($user);

            <span class="hljs-keyword">return</span> redirect(<span class="hljs-string">'/home'</span>);
        }

        <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'otp.login'</span>)-&gt;with(<span class="hljs-string">'error'</span>, <span class="hljs-string">'Your Otp is not correct'</span>);
    }
}
</code></pre>
<h2 id="heading-step-4">Step - 4</h2>
<p>Create Routes for OTP login and Verification, open <code>routes/web.php</code> and update the code at bottom.</p>
<pre><code class="lang-php">Route::controller(AuthOtpController::class)-&gt;group(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    Route::get(<span class="hljs-string">'/otp/login'</span>, <span class="hljs-string">'login'</span>)-&gt;name(<span class="hljs-string">'otp.login'</span>);
    Route::post(<span class="hljs-string">'/otp/generate'</span>, <span class="hljs-string">'generate'</span>)-&gt;name(<span class="hljs-string">'otp.generate'</span>);
    Route::get(<span class="hljs-string">'/otp/verification/{user_id}'</span>, <span class="hljs-string">'verification'</span>)-&gt;name(<span class="hljs-string">'otp.verification'</span>);
    Route::post(<span class="hljs-string">'/otp/login'</span>, <span class="hljs-string">'loginWithOtp'</span>)-&gt;name(<span class="hljs-string">'otp.getlogin'</span>);
});
</code></pre>
<h2 id="heading-step-5">Step - 5</h2>
<p>Create view files in <code>resources/views/auth</code> folder, 
First, create <code>otp-login.blade.php</code> and the code below.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.app'</span>)

@section(<span class="hljs-string">'content'</span>)
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;</span>{{ __(<span class="hljs-string">'OTP Login'</span>) }}&lt;/div&gt;

                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">body</span>"&gt;

                    @<span class="hljs-title">if</span> (<span class="hljs-title">session</span>('<span class="hljs-title">error</span>'))
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">danger</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"&gt; </span>{{session(<span class="hljs-string">'error'</span>)}} 
                    &lt;/div&gt;
                    @<span class="hljs-keyword">endif</span>

                    &lt;form method=<span class="hljs-string">"POST"</span> action=<span class="hljs-string">"{{ route('otp.generate') }}"</span>&gt;
                        @csrf

                        &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">mb</span>-3"&gt;
                            &lt;<span class="hljs-title">label</span> <span class="hljs-title">for</span>="<span class="hljs-title">mobile_no</span>" <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-4 <span class="hljs-title">col</span>-<span class="hljs-title">form</span>-<span class="hljs-title">label</span> <span class="hljs-title">text</span>-<span class="hljs-title">md</span>-<span class="hljs-title">end</span>"&gt;</span>{{ __(<span class="hljs-string">'Mobile No'</span>) }}&lt;/label&gt;

                            &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-6"&gt;
                                &lt;<span class="hljs-title">input</span> <span class="hljs-title">id</span>="<span class="hljs-title">mobile_no</span>" <span class="hljs-title">type</span>="<span class="hljs-title">text</span>" <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span> @<span class="hljs-title">error</span>('<span class="hljs-title">mobile_no</span>') <span class="hljs-title">is</span>-<span class="hljs-title">invalid</span> @<span class="hljs-title">enderror</span>" <span class="hljs-title">name</span>="<span class="hljs-title">mobile_no</span>" <span class="hljs-title">value</span>="</span>{{ old(<span class="hljs-string">'mobile_no'</span>) }}<span class="hljs-string">" required autocomplete="</span>mobile_no<span class="hljs-string">" autofocus placeholder="</span>Enter Your Registered Mobile Number<span class="hljs-string">"&gt;

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



                        &lt;div class="</span>row mb<span class="hljs-number">-0</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-8</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">"&gt;
                                    {{ __('Generate OTP') }}
                                &lt;/button&gt;

                                @if (Route::has('login'))
                                    &lt;a class="</span>btn btn-link<span class="hljs-string">" href="</span>{{ route(<span class="hljs-string">'login'</span>) }}<span class="hljs-string">"&gt;
                                        {{ __('Login With Username') }}
                                    &lt;/a&gt;
                                @endif
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection</span>
</code></pre>
<p>Now create another view file <code>otp-verification.blade.php</code> &amp; update the code below.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.app'</span>)

@section(<span class="hljs-string">'content'</span>)
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;</span>{{ __(<span class="hljs-string">'OTP Login'</span>) }}&lt;/div&gt;

                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">body</span>"&gt;
                    @<span class="hljs-title">if</span> (<span class="hljs-title">session</span>('<span class="hljs-title">success</span>'))
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">success</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"&gt; </span>{{session(<span class="hljs-string">'success'</span>)}} 
                    &lt;/div&gt;
                    @<span class="hljs-keyword">endif</span>

                    @<span class="hljs-keyword">if</span> (session(<span class="hljs-string">'error'</span>))
                    &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">danger</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"&gt; </span>{{session(<span class="hljs-string">'error'</span>)}} 
                    &lt;/div&gt;
                    @<span class="hljs-keyword">endif</span>

                    &lt;form method=<span class="hljs-string">"POST"</span> action=<span class="hljs-string">"{{ route('otp.getlogin') }}"</span>&gt;
                        @csrf
                        &lt;input type=<span class="hljs-string">"hidden"</span> name=<span class="hljs-string">"user_id"</span> value=<span class="hljs-string">"{<span class="hljs-subst">{$user_id}</span>}"</span> /&gt;
                        &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">mb</span>-3"&gt;
                            &lt;<span class="hljs-title">label</span> <span class="hljs-title">for</span>="<span class="hljs-title">mobile_no</span>" <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-4 <span class="hljs-title">col</span>-<span class="hljs-title">form</span>-<span class="hljs-title">label</span> <span class="hljs-title">text</span>-<span class="hljs-title">md</span>-<span class="hljs-title">end</span>"&gt;</span>{{ __(<span class="hljs-string">'OTP'</span>) }}&lt;/label&gt;

                            &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-6"&gt;
                                &lt;<span class="hljs-title">input</span> <span class="hljs-title">id</span>="<span class="hljs-title">otp</span>" <span class="hljs-title">type</span>="<span class="hljs-title">text</span>" <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span> @<span class="hljs-title">error</span>('<span class="hljs-title">otp</span>') <span class="hljs-title">is</span>-<span class="hljs-title">invalid</span> @<span class="hljs-title">enderror</span>" <span class="hljs-title">name</span>="<span class="hljs-title">otp</span>" <span class="hljs-title">value</span>="</span>{{ old(<span class="hljs-string">'otp'</span>) }}<span class="hljs-string">" required autocomplete="</span>otp<span class="hljs-string">" autofocus placeholder="</span>Enter OTP<span class="hljs-string">"&gt;

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



                        &lt;div class="</span>row mb<span class="hljs-number">-0</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-8</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">"&gt;
                                    {{ __('Login') }}
                                &lt;/button&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection</span>
</code></pre>
<h3 id="heading-complete-flow-will-look-like">Complete Flow will look like.</h3>
<p>Open the project and go to <code>/otp/login</code> and it will look like.
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mid5m6md25dij12tf9ct.png" alt="OTP LOGIN" /></p>
<p>As soon as you enter the registered mobile number, it will redirect you to the verification screen with OTP in the flash message.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sceec4mxid8bq3o5yori.png" alt="OTP Verification" /></p>
<p>After you enter the OTP, It will log in and redirect you to the dashboard.</p>
<p>I hope this will help login with <code>OTP</code> in LARAVEL 9.</p>
<h3 id="heading-complete-video-tutorial-on-youtube">Complete Video Tutorial on YouTube.</h3>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/6KWMHJtnImc">https://youtu.be/6KWMHJtnImc</a></div>
<p>If you face any issues while implementing, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[How to Login with USERNAME instead of Email in Laravel 9?]]></title><description><![CDATA[In this post, I am going to explain about login with a username instead of email in Laravel 9.
After Installing Laravel and Laravel Authentication open code project in a code editor & follow the steps below.
Step - 1
Add the username field in the use...]]></description><link>https://techtoolindia.com/how-to-login-with-username-instead-of-email-in-laravel-9</link><guid isPermaLink="true">https://techtoolindia.com/how-to-login-with-username-instead-of-email-in-laravel-9</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Laravel 9]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Sat, 23 Jul 2022 15:10:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1658588731563/EHVDX7n5u.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this post, I am going to explain about login with a username instead of email in Laravel 9.</p>
<p>After <a target="_blank" href="https://dev.to/shanisingh03/how-to-install-laravel-9-25c4">Installing Laravel</a> and <a target="_blank" href="https://dev.to/shanisingh03/how-to-make-login-registration-in-laravel-9-1p2n">Laravel Authentication</a> open code project in a code editor &amp; follow the steps below.</p>
<h2 id="heading-step-1">Step - 1</h2>
<p>Add the <code>username</code> field in the users table, for that create a migration to add a field.</p>
<pre><code class="lang-php">php artisan make:migration add_username_field_in_users_table
</code></pre>
<p>This command will create a file inside <code>database\migrations</code> folder.</p>
<p>Now update the file with the code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Migrations</span>\<span class="hljs-title">Migration</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Schema</span>\<span class="hljs-title">Blueprint</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Schema</span>;

<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Migration</span>
</span>{
    <span class="hljs-comment">/**
     * Run the migrations.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)
    </span>{
        Schema::table(<span class="hljs-string">'users'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) </span>{
            $table-&gt;string(<span class="hljs-string">'username'</span>)-&gt;after(<span class="hljs-string">'name'</span>);
        });
    }

    <span class="hljs-comment">/**
     * Reverse the migrations.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">down</span>(<span class="hljs-params"></span>)
    </span>{
        Schema::table(<span class="hljs-string">'users'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) </span>{
            $table-&gt;dropColumn(<span class="hljs-string">'username'</span>);
        });
    }
};
</code></pre>
<p>Now run the migration in order to add <code>username</code> in users table.</p>
<pre><code class="lang-php">php artisan migrate
</code></pre>
<h2 id="heading-step-2">Step - 2</h2>
<p>Now update the registration form so that the user can choose a username for login.</p>
<p>Open register view file <code>resources/views/auth/register.blade.php</code> and update the following code.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.app'</span>)

@section(<span class="hljs-string">'content'</span>)
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;</span>{{ __(<span class="hljs-string">'Register'</span>) }}&lt;/div&gt;

                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">body</span>"&gt;
                    &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">POST</span>" <span class="hljs-title">action</span>="</span>{{ route(<span class="hljs-string">'register'</span>) }}<span class="hljs-string">"&gt;
                        @csrf

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>name<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Name') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>name<span class="hljs-string">" type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'name'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>name<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'name'</span>) }}<span class="hljs-string">" required autocomplete="</span>name<span class="hljs-string">" autofocus&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>username<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Username') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>username<span class="hljs-string">" type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'username'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>username<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'username'</span>) }}<span class="hljs-string">" required autocomplete="</span>username<span class="hljs-string">" autofocus&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>email<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Email Address') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>email<span class="hljs-string">" type="</span>email<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'email'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>email<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'email'</span>) }}<span class="hljs-string">" required autocomplete="</span>email<span class="hljs-string">"&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>password<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Password') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>password<span class="hljs-string">" type="</span>password<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'password'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>password<span class="hljs-string">" required autocomplete="</span><span class="hljs-keyword">new</span>-password<span class="hljs-string">"&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>password-confirm<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Confirm Password') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>password-confirm<span class="hljs-string">" type="</span>password<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" name="</span>password_confirmation<span class="hljs-string">" required autocomplete="</span><span class="hljs-keyword">new</span>-password<span class="hljs-string">"&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;

                        &lt;div class="</span>row mb<span class="hljs-number">-0</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-6</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">"&gt;
                                    {{ __('Register') }}
                                &lt;/button&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection</span>
</code></pre>
<p>Now register form will look like</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vh8uyjqphygsydeny6sh.png" alt="Register Form" /></p>
<p>Next, we have to update the User Model, to update the User Model opens the file <code>app/Models/User.php</code> and update the following code.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

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

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Contracts</span>\<span class="hljs-title">Auth</span>\<span class="hljs-title">MustVerifyEmail</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Factories</span>\<span class="hljs-title">HasFactory</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Foundation</span>\<span class="hljs-title">Auth</span>\<span class="hljs-title">User</span> <span class="hljs-title">as</span> <span class="hljs-title">Authenticatable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Notifications</span>\<span class="hljs-title">Notifiable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Laravel</span>\<span class="hljs-title">Sanctum</span>\<span class="hljs-title">HasApiTokens</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Authenticatable</span>
</span>{
    <span class="hljs-keyword">use</span> <span class="hljs-title">HasApiTokens</span>, <span class="hljs-title">HasFactory</span>, <span class="hljs-title">Notifiable</span>;

    <span class="hljs-comment">/**
     * The attributes that are mass assignable.
     *
     * <span class="hljs-doctag">@var</span> array&lt;int, string&gt;
     */</span>
    <span class="hljs-keyword">protected</span> $fillable = [
        <span class="hljs-string">'name'</span>,
        <span class="hljs-string">'username'</span>,
        <span class="hljs-string">'email'</span>,
        <span class="hljs-string">'password'</span>,
    ];

    <span class="hljs-comment">/**
     * The attributes that should be hidden for serialization.
     *
     * <span class="hljs-doctag">@var</span> array&lt;int, string&gt;
     */</span>
    <span class="hljs-keyword">protected</span> $hidden = [
        <span class="hljs-string">'password'</span>,
        <span class="hljs-string">'remember_token'</span>,
    ];

    <span class="hljs-comment">/**
     * The attributes that should be cast.
     *
     * <span class="hljs-doctag">@var</span> array&lt;string, string&gt;
     */</span>
    <span class="hljs-keyword">protected</span> $casts = [
        <span class="hljs-string">'email_verified_at'</span> =&gt; <span class="hljs-string">'datetime'</span>,
    ];
}
</code></pre>
<p>Next, we have to update the <code>RegisterController</code>, Open file <code>app/Http/Controller/Auth/RegisterController.php</code> and update the code.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Auth</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Controller</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Providers</span>\<span class="hljs-title">RouteServiceProvider</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Foundation</span>\<span class="hljs-title">Auth</span>\<span class="hljs-title">RegistersUsers</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Hash</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Validator</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RegisterController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">/*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */</span>

    <span class="hljs-keyword">use</span> <span class="hljs-title">RegistersUsers</span>;

    <span class="hljs-comment">/**
     * Where to redirect users after registration.
     *
     * <span class="hljs-doctag">@var</span> string
     */</span>
    <span class="hljs-keyword">protected</span> $redirectTo = RouteServiceProvider::HOME;

    <span class="hljs-comment">/**
     * Create a new controller instance.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;middleware(<span class="hljs-string">'guest'</span>);
    }

    <span class="hljs-comment">/**
     * Get a validator for an incoming registration request.
     *
     * <span class="hljs-doctag">@param</span>  array  $data
     * <span class="hljs-doctag">@return</span> \Illuminate\Contracts\Validation\Validator
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">validator</span>(<span class="hljs-params"><span class="hljs-keyword">array</span> $data</span>)
    </span>{
        <span class="hljs-keyword">return</span> Validator::make($data, [
            <span class="hljs-string">'name'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>],
            <span class="hljs-string">'username'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'max:255'</span>],
            <span class="hljs-string">'email'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'email'</span>, <span class="hljs-string">'max:255'</span>, <span class="hljs-string">'unique:users'</span>],
            <span class="hljs-string">'password'</span> =&gt; [<span class="hljs-string">'required'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'min:8'</span>, <span class="hljs-string">'confirmed'</span>],
        ]);
    }

    <span class="hljs-comment">/**
     * Create a new user instance after a valid registration.
     *
     * <span class="hljs-doctag">@param</span>  array  $data
     * <span class="hljs-doctag">@return</span> \App\Models\User
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">create</span>(<span class="hljs-params"><span class="hljs-keyword">array</span> $data</span>)
    </span>{
        <span class="hljs-keyword">return</span> User::create([
            <span class="hljs-string">'name'</span> =&gt; $data[<span class="hljs-string">'name'</span>],
            <span class="hljs-string">'username'</span> =&gt; $data[<span class="hljs-string">'username'</span>],
            <span class="hljs-string">'email'</span> =&gt; $data[<span class="hljs-string">'email'</span>],
            <span class="hljs-string">'password'</span> =&gt; Hash::make($data[<span class="hljs-string">'password'</span>]),
        ]);
    }
}
</code></pre>
<h2 id="heading-step-3">Step - 3</h2>
<p>Next, you have to update the login form, and open the view file <code>resources/views/auth/login.blade.php</code>.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.app'</span>)

@section(<span class="hljs-string">'content'</span>)
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;</span>{{ __(<span class="hljs-string">'Login'</span>) }}&lt;/div&gt;

                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">body</span>"&gt;
                    &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">POST</span>" <span class="hljs-title">action</span>="</span>{{ route(<span class="hljs-string">'login'</span>) }}<span class="hljs-string">"&gt;
                        @csrf

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>username<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Username') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>username<span class="hljs-string">" type="</span>text<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'username'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>username<span class="hljs-string">" value="</span>{{ old(<span class="hljs-string">'username'</span>) }}<span class="hljs-string">" required autocomplete="</span>username<span class="hljs-string">" autofocus&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;label for="</span>password<span class="hljs-string">" class="</span>col-md<span class="hljs-number">-4</span> col-form-label text-md-end<span class="hljs-string">"&gt;{{ __('Password') }}&lt;/label&gt;

                            &lt;div class="</span>col-md<span class="hljs-number">-6</span><span class="hljs-string">"&gt;
                                &lt;input id="</span>password<span class="hljs-string">" type="</span>password<span class="hljs-string">" class="</span>form-control @<span class="hljs-built_in">error</span>(<span class="hljs-string">'password'</span>) is-invalid @enderror<span class="hljs-string">" name="</span>password<span class="hljs-string">" required autocomplete="</span>current-password<span class="hljs-string">"&gt;

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

                        &lt;div class="</span>row mb<span class="hljs-number">-3</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-6</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                &lt;div class="</span>form-check<span class="hljs-string">"&gt;
                                    &lt;input class="</span>form-check-input<span class="hljs-string">" type="</span>checkbox<span class="hljs-string">" name="</span>remember<span class="hljs-string">" id="</span>remember<span class="hljs-string">" {{ old('remember') ? 'checked' : '' }}&gt;

                                    &lt;label class="</span>form-check-label<span class="hljs-string">" for="</span>remember<span class="hljs-string">"&gt;
                                        {{ __('Remember Me') }}
                                    &lt;/label&gt;
                                &lt;/div&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;

                        &lt;div class="</span>row mb<span class="hljs-number">-0</span><span class="hljs-string">"&gt;
                            &lt;div class="</span>col-md<span class="hljs-number">-8</span> offset-md<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
                                &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">"&gt;
                                    {{ __('Login') }}
                                &lt;/button&gt;

                                @if (Route::has('password.request'))
                                    &lt;a class="</span>btn btn-link<span class="hljs-string">" href="</span>{{ route(<span class="hljs-string">'password.request'</span>) }}<span class="hljs-string">"&gt;
                                        {{ __('Forgot Your Password?') }}
                                    &lt;/a&gt;
                                @endif
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection</span>
</code></pre>
<p>Next, you have to update <code>LoginController</code> open <code>app/Http/Controller/Auth/LoginController.php</code> and update the code.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Auth</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Controller</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Providers</span>\<span class="hljs-title">RouteServiceProvider</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Foundation</span>\<span class="hljs-title">Auth</span>\<span class="hljs-title">AuthenticatesUsers</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LoginController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">/*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */</span>

    <span class="hljs-keyword">use</span> <span class="hljs-title">AuthenticatesUsers</span>;

    <span class="hljs-comment">/**
     * Where to redirect users after login.
     *
     * <span class="hljs-doctag">@var</span> string
     */</span>
    <span class="hljs-keyword">protected</span> $redirectTo = RouteServiceProvider::HOME;

    <span class="hljs-comment">/**
     * Create a new controller instance.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;middleware(<span class="hljs-string">'guest'</span>)-&gt;except(<span class="hljs-string">'logout'</span>);
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">username</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'username'</span>;
    }
}
</code></pre>
<p>Now the login form will look like this.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewrkycsuplwwnr1l1m9f.png" alt="Login Screen" /></p>
<p>I hope this will help login with <code>username</code> in Laravel 9.</p>
<p>Here you will get a complete video tutorial on Youtube.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/y0HBjmS4Kho">https://youtu.be/y0HBjmS4Kho</a></div>
<p>If you face any issues while implementing, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[How to upload an Image In Laravel 9?]]></title><description><![CDATA[In this post, I will explain all about Image upload in LARAVEL.
After Installing Laravel open the code project in the code editor & follow the steps below.
Step - 1
Create a Controller to handle all image upload operations by running the command belo...]]></description><link>https://techtoolindia.com/how-to-upload-an-image-in-laravel-9</link><guid isPermaLink="true">https://techtoolindia.com/how-to-upload-an-image-in-laravel-9</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Mon, 11 Jul 2022 09:32:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1657531755917/Z_qbmWbs5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this post, I will explain all about Image upload in LARAVEL.</p>
<p>After <a target="_blank" href="https://dev.to/shanisingh03/how-to-install-laravel-9-25c4">Installing Laravel</a> open the code project in the code editor &amp; follow the steps below.</p>
<h2 id="heading-step-1">Step - 1</h2>
<p>Create a Controller to handle all image upload operations by running the command below.</p>
<pre><code class="lang-php">php artisan make:controller ImageController
</code></pre>
<p>this will create a controller inside <code>app\Http\Controllers</code> folder.</p>
<p>Now update your controller with the following codes.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>;

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

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ImageController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">// View File To Upload Image</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">'image-form'</span>);
    }

    <span class="hljs-comment">// Store Image</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">storeImage</span>(<span class="hljs-params">Request $request</span>)
    </span>{
        $request-&gt;validate([
            <span class="hljs-string">'image'</span> =&gt; <span class="hljs-string">'required|image|mimes:png,jpg,jpeg|max:2048'</span>
        ]);

        $imageName = time().<span class="hljs-string">'.'</span>.$request-&gt;image-&gt;extension();

        <span class="hljs-comment">// Public Folder</span>
        $request-&gt;image-&gt;move(public_path(<span class="hljs-string">'images'</span>), $imageName);

        <span class="hljs-comment">// //Store in Storage Folder</span>
        <span class="hljs-comment">// $request-&gt;image-&gt;storeAs('images', $imageName);</span>

        <span class="hljs-comment">// // Store in S3</span>
        <span class="hljs-comment">// $request-&gt;image-&gt;storeAs('images', $imageName, 's3');</span>

        <span class="hljs-comment">//Store IMage in DB </span>


        <span class="hljs-keyword">return</span> back()-&gt;with(<span class="hljs-string">'success'</span>, <span class="hljs-string">'Image uploaded Successfully!'</span>)
        -&gt;with(<span class="hljs-string">'image'</span>, $imageName);
    }
}
</code></pre>
<h2 id="heading-step-2">Step - 2</h2>
<p>The next thing is to update routes, to update it open <code>routes/web.php</code> file and add the below routes.</p>
<pre><code class="lang-php">Route::controller(ImageController::class)-&gt;group(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    Route::get(<span class="hljs-string">'/image-upload'</span>, <span class="hljs-string">'index'</span>)-&gt;name(<span class="hljs-string">'image.form'</span>);
    Route::post(<span class="hljs-string">'/upload-image'</span>, <span class="hljs-string">'storeImage'</span>)-&gt;name(<span class="hljs-string">'image.store'</span>);
});
</code></pre>
<h2 id="heading-step-3">Step - 3</h2>
<p>Now it's time to create a view file, open <code>resources/views</code> folder and create a file named <code>image-form.blade.php</code> and update the file with the code below.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'app'</span>)

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

    &lt;!-- Container (Contact Section) --&gt;
    &lt;div id=<span class="hljs-string">"contact"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
        &lt;<span class="hljs-title">h1</span> <span class="hljs-title">class</span>="<span class="hljs-title">text</span>-<span class="hljs-title">center</span>" <span class="hljs-title">style</span>="<span class="hljs-title">margin</span>-<span class="hljs-title">top</span>: 100<span class="hljs-title">px</span>"&gt;<span class="hljs-title">Image</span> <span class="hljs-title">Upload</span>&lt;/<span class="hljs-title">h1</span>&gt;

        @<span class="hljs-title">if</span> ($<span class="hljs-title">message</span> = <span class="hljs-title">Session</span>::<span class="hljs-title">get</span>('<span class="hljs-title">success</span>'))
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">success</span> <span class="hljs-title">alert</span>-<span class="hljs-title">block</span>"&gt;
                &lt;<span class="hljs-title">strong</span>&gt;</span>{{$message}}&lt;/strong&gt;
            &lt;/div&gt;

            &lt;img src=<span class="hljs-string">"{{ asset('images/'.Session::get('image')) }}"</span> /&gt;
        @<span class="hljs-keyword">endif</span>

        &lt;form method=<span class="hljs-string">"POST"</span> action=<span class="hljs-string">"{{ route('image.store') }}"</span> enctype=<span class="hljs-string">"multipart/form-data"</span>&gt;
            @csrf
            &lt;input type=<span class="hljs-string">"file"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span>" <span class="hljs-title">name</span>="<span class="hljs-title">image</span>" /&gt;

            &lt;<span class="hljs-title">button</span> <span class="hljs-title">type</span>="<span class="hljs-title">submit</span>" <span class="hljs-title">class</span>="<span class="hljs-title">btn</span> <span class="hljs-title">btn</span>-<span class="hljs-title">sm</span>"&gt;<span class="hljs-title">Upload</span>&lt;/<span class="hljs-title">button</span>&gt;
        &lt;/<span class="hljs-title">form</span>&gt;

    &lt;/<span class="hljs-title">div</span>&gt;
@<span class="hljs-title">endsection</span></span>
</code></pre>
<p>Now if you go to the browser and visit <code>/image-upload</code> you will see the image upload option.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1ao0qw2e7ytf5nx7pg9.png" alt="Image Upload" /></p>
<p>and once you select an image and upload it you will see the success message with the image.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mm16p79eje877f6l4unu.png" alt="Image Uploaded" /></p>
<p>Here you will get a complete video tutorial on Youtube.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/ZFc2wASN2xw">https://youtu.be/ZFc2wASN2xw</a></div>
<p>If you face any issues while implementing, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[Laravel 9 Form Validation]]></title><description><![CDATA[In this post, I am going to cover A to Z about Laravel Validation.
Things we will talk about in this post.

After Installing Laravel we will create a sample form to see our validation.
1 - Create Form
To create a form in resources/views folder create...]]></description><link>https://techtoolindia.com/laravel-9-form-validation</link><guid isPermaLink="true">https://techtoolindia.com/laravel-9-form-validation</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Thu, 16 Jun 2022 20:37:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1655411701306/isqUJz9nT.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this post, I am going to cover A to Z about Laravel Validation.</p>
<p>Things we will talk about in this post.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tj7rhjqz3rm6prqtfm6v.png" alt="Validation Topics" /></p>
<p>After <a target="_blank" href="https://dev.to/shanisingh03/how-to-install-laravel-9-25c4">Installing Laravel</a> we will create a sample form to see our validation.</p>
<h2 id="heading-1-create-form">1 - Create Form</h2>
<p>To create a form in <code>resources/views</code> folder create a view file <code>form.blade.php</code>.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'app'</span>)

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

    &lt;!-- Container (Contact Section) --&gt;
    &lt;div id=<span class="hljs-string">"contact"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
        &lt;<span class="hljs-title">h3</span> <span class="hljs-title">class</span>="<span class="hljs-title">text</span>-<span class="hljs-title">center</span>"&gt;<span class="hljs-title">Create</span> <span class="hljs-title">User</span>&lt;/<span class="hljs-title">h3</span>&gt;
        &lt;<span class="hljs-title">p</span> <span class="hljs-title">class</span>="<span class="hljs-title">text</span>-<span class="hljs-title">center</span>"&gt;&lt;<span class="hljs-title">em</span>&gt;<span class="hljs-title">Register</span> <span class="hljs-title">Here</span>&lt;/<span class="hljs-title">em</span>&gt;&lt;/<span class="hljs-title">p</span>&gt;

        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span>"&gt;

            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-12"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span>"&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">sm</span>-6 <span class="hljs-title">form</span>-<span class="hljs-title">group</span>"&gt;
                        &lt;<span class="hljs-title">input</span> <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span>" <span class="hljs-title">id</span>="<span class="hljs-title">name</span>" <span class="hljs-title">name</span>="<span class="hljs-title">name</span>" <span class="hljs-title">placeholder</span>="<span class="hljs-title">Full</span> <span class="hljs-title">Name</span>" <span class="hljs-title">type</span>="<span class="hljs-title">text</span>" <span class="hljs-title">required</span>&gt;
                    &lt;/<span class="hljs-title">div</span>&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">sm</span>-6 <span class="hljs-title">form</span>-<span class="hljs-title">group</span>"&gt;
                        &lt;<span class="hljs-title">input</span> <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span>" <span class="hljs-title">id</span>="<span class="hljs-title">email</span>" <span class="hljs-title">name</span>="<span class="hljs-title">email</span>" <span class="hljs-title">placeholder</span>="<span class="hljs-title">Email</span>" <span class="hljs-title">type</span>="<span class="hljs-title">email</span>" <span class="hljs-title">required</span>&gt;
                    &lt;/<span class="hljs-title">div</span>&gt;
                &lt;/<span class="hljs-title">div</span>&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span>"&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">sm</span>-6 <span class="hljs-title">form</span>-<span class="hljs-title">group</span>"&gt;
                        &lt;<span class="hljs-title">input</span> <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span>" <span class="hljs-title">id</span>="<span class="hljs-title">gender</span>" <span class="hljs-title">name</span>="<span class="hljs-title">gender</span>" <span class="hljs-title">placeholder</span>="<span class="hljs-title">Gender</span>" <span class="hljs-title">type</span>="<span class="hljs-title">text</span>" <span class="hljs-title">required</span>&gt;
                    &lt;/<span class="hljs-title">div</span>&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">sm</span>-6 <span class="hljs-title">form</span>-<span class="hljs-title">group</span>"&gt;
                        &lt;<span class="hljs-title">input</span> <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span>" <span class="hljs-title">id</span>="<span class="hljs-title">password</span>" <span class="hljs-title">name</span>="<span class="hljs-title">password</span>" <span class="hljs-title">placeholder</span>="<span class="hljs-title">Password</span>" <span class="hljs-title">type</span>="<span class="hljs-title">password</span>" <span class="hljs-title">required</span>&gt;
                    &lt;/<span class="hljs-title">div</span>&gt;
                &lt;/<span class="hljs-title">div</span>&gt;

                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span>"&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-12 <span class="hljs-title">form</span>-<span class="hljs-title">group</span>"&gt;
                        &lt;<span class="hljs-title">button</span> <span class="hljs-title">class</span>="<span class="hljs-title">btn</span> <span class="hljs-title">pull</span>-<span class="hljs-title">right</span>" <span class="hljs-title">type</span>="<span class="hljs-title">submit</span>"&gt;<span class="hljs-title">Send</span>&lt;/<span class="hljs-title">button</span>&gt;
                    &lt;/<span class="hljs-title">div</span>&gt;
                &lt;/<span class="hljs-title">div</span>&gt;
            &lt;/<span class="hljs-title">div</span>&gt;
        &lt;/<span class="hljs-title">div</span>&gt;
    &lt;/<span class="hljs-title">div</span>&gt;
@<span class="hljs-title">endsection</span></span>
</code></pre>
<h2 id="heading-2-create-validation">2 - Create Validation</h2>
<p>To create a validation Rule write inside the controller</p>
<pre><code class="lang-php">$request-&gt;validate([
            <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'required'</span>,
            <span class="hljs-string">'email'</span> =&gt; <span class="hljs-string">'required'</span>,
            <span class="hljs-string">'gender'</span> =&gt; <span class="hljs-string">'required'</span>,
            <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'required'</span>,
        ]);
</code></pre>
<p>To display the error message on Input Fields</p>
<pre><code class="lang-php">@<span class="hljs-built_in">error</span>(<span class="hljs-string">'name'</span>)
   &lt;span <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">text</span>-<span class="hljs-title">danger</span>"&gt;</span>{{$message}}&lt;/span&gt;
@enderror
</code></pre>
<h2 id="heading-3-create-validation-using-validator-facade">3 - Create Validation Using Validator Facade</h2>
<p>To create validation using Validator Facade we can write in the controller</p>
<pre><code class="lang-php">$validate = Validator::make($request-&gt;all(), [
            <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'required|min:5'</span>,
            <span class="hljs-string">'email'</span> =&gt; <span class="hljs-string">'required'</span>,
            <span class="hljs-string">'gender'</span> =&gt; <span class="hljs-string">'required'</span>,
            <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'required'</span>,
        ],[
            <span class="hljs-string">'name.required'</span> =&gt; <span class="hljs-string">'Name is must.'</span>,
            <span class="hljs-string">'name.min'</span> =&gt; <span class="hljs-string">'Name must have 5 char.'</span>,
        ]);
<span class="hljs-keyword">if</span>($validate-&gt;fails()){
  <span class="hljs-keyword">return</span> back()-&gt;withErrors($validate-&gt;errors())-&gt;withInput();
}
</code></pre>
<h2 id="heading-4-create-a-request-file-for-validation">4 - Create a Request File For Validation</h2>
<p>To Create a Request File we have to run a command </p>
<pre><code class="lang-php">php artisan make:request FormDataRequest
</code></pre>
<p>This will create a file inside <code>App\Http\Requests</code> folder.
The file will be like this.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Requests</span>;

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

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">FormDataRequest</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FormRequest</span>
</span>{
    <span class="hljs-comment">/**
     * Determine if the user is authorized to make this request.
     *
     * <span class="hljs-doctag">@return</span> bool
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">authorize</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }

    <span class="hljs-comment">/**
     * Get the validation rules that apply to the request.
     *
     * <span class="hljs-doctag">@return</span> array&lt;string, mixed&gt;
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rules</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'required|min:5'</span>,
            <span class="hljs-string">'email'</span> =&gt; <span class="hljs-string">'required'</span>,
            <span class="hljs-string">'gender'</span> =&gt; <span class="hljs-string">'required'</span>,
            <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'required'</span>,
        ];
    }

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">messages</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">'name.required'</span> =&gt; <span class="hljs-string">'Name is Must'</span>,
            <span class="hljs-string">'name.min'</span> =&gt; <span class="hljs-string">'Name Must be 5 Chr.'</span>,
        ];
    }
}
</code></pre>
<p>Here you will get a complete video tutorial on Youtube.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/YjAT4IVz0dg">https://youtu.be/YjAT4IVz0dg</a></div>
<p>If you face any issues while implementing, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[Laravel Middleware - A Complete guide]]></title><description><![CDATA[Today we will take a detailed look into Laravel Middleware, and will understand its use of it.
What is Middleware?
A Middleware is like a bridge between HTTP requests and responses. it provides a mechanism for inspecting and filtering HTTP requests e...]]></description><link>https://techtoolindia.com/laravel-middleware-a-complete-guide</link><guid isPermaLink="true">https://techtoolindia.com/laravel-middleware-a-complete-guide</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Thu, 09 Jun 2022 16:51:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1654793205106/ssXOjES2h.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today we will take a detailed look into Laravel Middleware, and will understand its use of it.</p>
<h2 id="heading-what-is-middleware">What is Middleware?</h2>
<p>A Middleware is like a bridge between HTTP requests and responses. it provides a mechanism for inspecting and filtering HTTP requests entering your application.</p>
<p>Let's understand the Middleware by jumping into the code directly. After <a target="_blank" href="https://dev.to/shanisingh03/how-to-install-laravel-9-25c4">Installing Laravel</a> let's see how we can create and use Middleware.</p>
<h2 id="heading-how-to-create-a-middleware">How to Create a Middleware?</h2>
<p>For creating a middleware we have to run a command, Let's say for creating a middleware to check the year in request named 'CheckYear'.</p>
<pre><code class="lang-php">php artisan make:middleware CheckYear
</code></pre>
<h2 id="heading-add-a-condition-to-middleware">Add a condition to Middleware</h2>
<p>Let's Add a logic to add conditions in Middleware to check the year.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Middleware</span>;

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

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CheckYear</span>
</span>{
    <span class="hljs-comment">/**
     * Handle an incoming request.
     *
     * <span class="hljs-doctag">@param</span>  \Illuminate\Http\Request  $request
     * <span class="hljs-doctag">@param</span>  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * <span class="hljs-doctag">@param</span> String $year
     * <span class="hljs-doctag">@return</span> \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params">Request $request, <span class="hljs-built_in">Closure</span> $next, $year</span>)
    </span>{

        <span class="hljs-keyword">if</span>($request-&gt;has(<span class="hljs-string">'year'</span>) &amp;&amp; ($request-&gt;year == $year)){

            <span class="hljs-keyword">return</span> $next($request);
        }

        <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'welcome'</span>);
    }
}
</code></pre>
<h2 id="heading-apply-middleware-in-routeswebphp">Apply Middleware in <code>routes/web.php</code></h2>
<pre><code class="lang-php">Route::get(<span class="hljs-string">'/user/create'</span>, [App\Http\Controllers\UserController::class, <span class="hljs-string">'createUser'</span>])-&gt;middleware([<span class="hljs-string">'check-year:2022'</span>]);

Route::get(<span class="hljs-string">'/user/new'</span>, [App\Http\Controllers\UserController::class, <span class="hljs-string">'createUser'</span>])-&gt;middleware([<span class="hljs-string">'check-year:2023'</span>]);
</code></pre>
<p>You can create any other middleware and use it as per your requirement.</p>
<p>Here you will get a complete video tutorial on Youtube.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/I2N1jAz8nxY">https://youtu.be/I2N1jAz8nxY</a></div>
<p>If you face any issues while implementing, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[Laravel Migration - A Complete Tutorial]]></title><description><![CDATA[Laravel migration is like a version management tool of DATABASE.

Let's understand this better.
After Installing Laravel, let's understand migration.
Create a migration and understand the structure
To generate a migration you need to run a command
ph...]]></description><link>https://techtoolindia.com/laravel-migration-a-complete-tutorial</link><guid isPermaLink="true">https://techtoolindia.com/laravel-migration-a-complete-tutorial</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><category><![CDATA[migration]]></category><category><![CDATA[Databases]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Tue, 07 Jun 2022 21:15:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1654636220450/N_uS29F82.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Laravel migration is like a version management tool of DATABASE.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gtufbeukkkt4aq803mqj.png" alt="Laravel Migration" /></p>
<p>Let's understand this better.</p>
<p>After <a target="_blank" href="https://dev.to/shanisingh03/how-to-install-laravel-9-25c4">Installing Laravel</a>, let's understand migration.</p>
<h2 id="heading-create-a-migration-and-understand-the-structure">Create a migration and understand the structure</h2>
<p>To generate a migration you need to run a command</p>
<pre><code class="lang-php">php artisan make:migration create_contacts_table
</code></pre>
<p>this will generate a file in <code>database\migrations</code> folder.</p>
<p>The file consists of a new class extending the migration class of LARAVEL.</p>
<p>The new class consist of 2 major function <code>up()</code> &amp; <code>down()</code>.
The <code>up()</code> function holds all information about migrating the file.</p>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)
</span>{
    Schema::create(<span class="hljs-string">'contacts'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) 
    </span>{
            $table-&gt;id();
            $table-&gt;string(<span class="hljs-string">'name'</span>);
            $table-&gt;string(<span class="hljs-string">'mobile_no'</span>);
            $table-&gt;boolean(<span class="hljs-string">'status'</span>);
            $table-&gt;timestamps();
    });
}
</code></pre>
<p>whereas the <code>down()</code> function holds information about reversing the migration action.</p>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">down</span>(<span class="hljs-params"></span>)
</span>{
    Schema::dropIfExists(<span class="hljs-string">'contacts'</span>);
}
</code></pre>
<h2 id="heading-run-andamp-rollback-the-migration">Run &amp; Rollback The Migration</h2>
<p>To run a migration we need to use the command</p>
<pre><code class="lang-php">php artisan migrate
</code></pre>
<p>For rolling back the latest migration we have a command </p>
<pre><code class="lang-php">php artisan migrate:rollback
</code></pre>
<p>when we have to roll back to specific steps we can pass steps in the rollback command like</p>
<pre><code class="lang-php">php artisan migrate:rollback --step=<span class="hljs-number">3</span>
</code></pre>
<p>this will roll back the migration up to 3 steps starting from the latest.</p>
<h2 id="heading-addingupdating-columns-in-table">Adding/Updating Columns in Table</h2>
<p>We need to generate a migration file similar to what we have created while creating the migration to perform any task.</p>
<p>the only change will be there in the migration name, always try to write the migration name descriptive which helps LARAVEL to understand the table name in migrations.
For e.g. Updating the column <code>name</code> we should run commands like</p>
<pre><code class="lang-php">php artisan make:migration update_name_column_in_contacts_table
</code></pre>
<p>Read more at <a target="_blank" href="https://laravel.com/docs/9.x/migrations#columns">Laravel Doc</a></p>
<h2 id="heading-column-modifiers">Column Modifiers</h2>
<p>Column Modifiers are nothing but a predefined function available in LARAVEL Migration by using that you can make any column <code>nullable</code>, Set Column <code>default</code> and many more.</p>
<p>You can check the available <a target="_blank" href="https://laravel.com/docs/9.x/migrations#column-modifiers">Laravel Column Modifier</a>.</p>
<h2 id="heading-addrenameremove-database-indexes">Add/Rename/Remove Database Indexes</h2>
<p>Laravel Migration supports a few types of INDEXES for e.g.</p>
<pre><code class="lang-php"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Schema</span>\<span class="hljs-title">Blueprint</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Schema</span>;

Schema::table(<span class="hljs-string">'users'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) </span>{
    $table-&gt;index(<span class="hljs-string">'email'</span>);
});
</code></pre>
<p>For renaming a index you can use <code>renameIndex()</code> for e.g.</p>
<pre><code class="lang-php">$table-&gt;renameIndex(<span class="hljs-string">'email'</span>, <span class="hljs-string">'mobile_no'</span>);
</code></pre>
<p>For dropping a index you can use <code>dropIndex()</code> for e.g.</p>
<pre><code class="lang-php">$table-&gt;dropIndex(<span class="hljs-string">'email'</span>);
</code></pre>
<h2 id="heading-foreign-key-constraints">Foreign Key Constraints</h2>
<p>Laravel also provides support for creating foreign key constraints, which are used to force referential integrity at the database level. </p>
<pre><code class="lang-php">$table-&gt;foreignId(<span class="hljs-string">'user_id'</span>)
      -&gt;constrained(<span class="hljs-string">'users'</span>)
      -&gt;cascadeOnUpdate()
      -&gt;cascadeOnDelete();
</code></pre>
<p>The Complete Video Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/EB2qi8o845k">https://youtu.be/EB2qi8o845k</a></div>
<p>If you face any issues while implementing, please comment your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[How to reset the password in LARAVEL 9?]]></title><description><![CDATA[Send Forgot Password EMAIL to reset password.
We have already covered Laravel installation and Laravel Auth Scaffolding.
Next, We will cover forgot password flow using Laravel/UI.
Step 1
Gather SMTP Details, you can use any SMTP but for this tutorial...]]></description><link>https://techtoolindia.com/how-to-reset-the-password-in-laravel-9</link><guid isPermaLink="true">https://techtoolindia.com/how-to-reset-the-password-in-laravel-9</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Thu, 02 Jun 2022 19:48:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1654199345167/SXjwKAjhw.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-send-forgot-password-email-to-reset-password">Send Forgot Password EMAIL to reset password.</h2>
<p>We have already covered <a target="_blank" href="https://dev.to/shanisingh03/how-to-install-laravel-9-25c4">Laravel installation</a> and <a target="_blank" href="https://dev.to/shanisingh03/how-to-make-login-registration-in-laravel-9-1p2n">Laravel Auth Scaffolding</a>.</p>
<p>Next, We will cover forgot password flow using <a target="_blank" href="https://github.com/laravel/ui">Laravel/UI</a>.</p>
<h2 id="heading-step-1">Step 1</h2>
<p>Gather SMTP Details, you can use any SMTP but for this tutorial I am going to use <a target="_blank" href="https://mailtrap.io/">MailTrap</a>, this is an email testing tool you can use while developing any SMTP feature.</p>
<p>The Detail we require are</p>
<pre><code class="lang-php">MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=<span class="hljs-number">2525</span>
MAIL_USERNAME=<span class="hljs-comment">#############</span>
MAIL_PASSWORD=<span class="hljs-comment">############</span>
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=<span class="hljs-string">"test@test.com"</span>
MAIL_FROM_NAME=<span class="hljs-string">"${APP_NAME}"</span>
</code></pre>
<p>We have to update these details in <code>.env</code> file.</p>
<h2 id="heading-step-2">Step 2</h2>
<p>Now go to password reset route <code>/password/reset</code> you will see the reset password page.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gua0ktv9du68zh1behem.png" alt="Reset Password" /></p>
<p>Now enter the registered email address and click on Send Password Link.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/auy6l3j5srd6uts6n9lz.png" alt="Email Link Sent" /></p>
<p>You should get an email in MAILTRAP Inbox.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwd9imgzb4nrw10e5ahp.png" alt="Reset Email Look Like" /></p>
<p>Once you click on Reset Password Button from Email you will land on the Change password screen.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmkek9k8bd9meuy213kc.png" alt="Reset Password Page" /></p>
<p>After you enter a new password you will redirect to the homepage.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxf7ab149vgdxhnfgbuo.png" alt="Reset Password Success" /></p>
<p>The Complete Video Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/Y54cfciVQaM">https://youtu.be/Y54cfciVQaM</a></div>
<p>If you face any issues while implementing, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/TechToolIndia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[Laravel 9 Basic Routing, Views & Layouts Tutorial.]]></title><description><![CDATA[In this post, you will learn about basic routing, and understanding Views & Layouts.
Routes
Laravel Routes are inside routes folder, there are 2 files web.php for all website routes and api.php for all API routes.
There are 4 types of route methods G...]]></description><link>https://techtoolindia.com/laravel-9-basic-routing-views-and-layouts-tutorial</link><guid isPermaLink="true">https://techtoolindia.com/laravel-9-basic-routing-views-and-layouts-tutorial</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><category><![CDATA[PHP]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Mon, 30 May 2022 08:19:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1653898451624/M3ncwA4sy.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this post, you will learn about basic routing, and understanding Views &amp; Layouts.</p>
<h2 id="heading-routes">Routes</h2>
<p>Laravel Routes are inside <code>routes</code> folder, there are 2 files <code>web.php</code> for all website routes and <code>api.php</code> for all API routes.</p>
<p>There are 4 types of route methods <code>GET, POST, PUT, DELETE</code>.</p>
<p>e.g. route will look like.</p>
<pre><code class="lang-php">Route::get(<span class="hljs-string">'/home'</span>, [App\Http\Controllers\HomeController::class, <span class="hljs-string">'index'</span>])-&gt;name(<span class="hljs-string">'home'</span>);
</code></pre>
<h2 id="heading-views">Views</h2>
<p>Laravel Views files are inside <code>resources/views</code> folder
a sample view file looks like.</p>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.app'</span>)

@section(<span class="hljs-string">'content'</span>)
&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;</span>{{ __(<span class="hljs-string">'Dashboard'</span>) }}&lt;/div&gt;

                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">body</span>"&gt;
                    @<span class="hljs-title">if</span> (<span class="hljs-title">session</span>('<span class="hljs-title">status</span>'))
                        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">success</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"&gt;
                            </span>{{ session(<span class="hljs-string">'status'</span>) }}
                        &lt;/div&gt;
                    @<span class="hljs-keyword">endif</span>

                    {{ __(<span class="hljs-string">'You are logged in! Thanks'</span>) }}
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection
</code></pre>
<h2 id="heading-layouts">Layouts</h2>
<p>Layouts are generally common for whole website/Web Apps.
It contains basic HTML Structure and yield some part from the child, Like Title, Content etc.</p>
<p>Sample Layout Looks like.</p>
<pre><code class="lang-php">&lt;!doctype html&gt;
&lt;html lang=<span class="hljs-string">"{{ str_replace('_', '-', app()-&gt;getLocale()) }}"</span>&gt;
&lt;head&gt;
    &lt;meta charset=<span class="hljs-string">"utf-8"</span>&gt;
    &lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1"</span>&gt;

    &lt;!-- CSRF Token --&gt;
    &lt;meta name=<span class="hljs-string">"csrf-token"</span> content=<span class="hljs-string">"{{ csrf_token() }}"</span>&gt;

    &lt;title&gt;{{ config(<span class="hljs-string">'app.name'</span>, <span class="hljs-string">'Laravel'</span>) }}&lt;/title&gt;

    &lt;!-- Scripts --&gt;
    &lt;script src=<span class="hljs-string">"{{ asset('js/app.js') }}"</span> defer&gt;&lt;/script&gt;

    &lt;!-- Fonts --&gt;
    &lt;link rel=<span class="hljs-string">"dns-prefetch"</span> href=<span class="hljs-string">"//fonts.gstatic.com"</span>&gt;
    &lt;link href=<span class="hljs-string">"https://fonts.googleapis.com/css?family=Nunito"</span> rel=<span class="hljs-string">"stylesheet"</span>&gt;

    &lt;!-- Styles --&gt;
    &lt;link href=<span class="hljs-string">"{{ asset('css/app.css') }}"</span> rel=<span class="hljs-string">"stylesheet"</span>&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div id=<span class="hljs-string">"app"</span>&gt;
        &lt;nav <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">navbar</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">expand</span>-<span class="hljs-title">md</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">light</span> <span class="hljs-title">bg</span>-<span class="hljs-title">white</span> <span class="hljs-title">shadow</span>-<span class="hljs-title">sm</span>"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;
                &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">brand</span>" <span class="hljs-title">href</span>="</span>{{ url(<span class="hljs-string">'/'</span>) }}<span class="hljs-string">"&gt;
                    {{ config('app.name', 'Laravel') }}
                &lt;/a&gt;
                &lt;button class="</span>navbar-toggler<span class="hljs-string">" type="</span>button<span class="hljs-string">" data-bs-toggle="</span>collapse<span class="hljs-string">" data-bs-target="</span><span class="hljs-comment">#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}"&gt;</span>
                    &lt;span <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">toggler</span>-<span class="hljs-title">icon</span>"&gt;&lt;/<span class="hljs-title">span</span>&gt;
                &lt;/<span class="hljs-title">button</span>&gt;

                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">collapse</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">collapse</span>" <span class="hljs-title">id</span>="<span class="hljs-title">navbarSupportedContent</span>"&gt;
                    &lt;!-- <span class="hljs-title">Left</span> <span class="hljs-title">Side</span> <span class="hljs-title">Of</span> <span class="hljs-title">Navbar</span> --&gt;
                    &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">nav</span> <span class="hljs-title">me</span>-<span class="hljs-title">auto</span>"&gt;
                        @<span class="hljs-title">auth</span>
                            &lt;<span class="hljs-title">li</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">item</span>"&gt;
                                &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{ route(<span class="hljs-string">'home'</span>) }}<span class="hljs-string">"&gt;Home &lt;/a&gt;
                            &lt;/li&gt;
                            &lt;li class="</span>nav-item<span class="hljs-string">"&gt;
                                &lt;a href="</span>{{ route(<span class="hljs-string">'new-home'</span>) }}<span class="hljs-string">"&gt; New Home&lt;/a&gt;
                            &lt;/li&gt;
                        @endauth
                    &lt;/ul&gt;

                    &lt;!-- Right Side Of Navbar --&gt;
                    &lt;ul class="</span>navbar-nav ms-auto<span class="hljs-string">"&gt;
                        &lt;!-- Authentication Links --&gt;
                        @guest
                            @if (Route::has('login'))
                                &lt;li class="</span>nav-item<span class="hljs-string">"&gt;
                                    &lt;a class="</span>nav-link<span class="hljs-string">" href="</span>{{ route(<span class="hljs-string">'login'</span>) }}<span class="hljs-string">"&gt;{{ __('Login') }}&lt;/a&gt;
                                &lt;/li&gt;
                            @endif

                            @if (Route::has('register'))
                                &lt;li class="</span>nav-item<span class="hljs-string">"&gt;
                                    &lt;a class="</span>nav-link<span class="hljs-string">" href="</span>{{ route(<span class="hljs-string">'register'</span>) }}<span class="hljs-string">"&gt;{{ __('Register') }}&lt;/a&gt;
                                &lt;/li&gt;
                            @endif
                        @else
                            &lt;li class="</span>nav-item dropdown<span class="hljs-string">"&gt;
                                &lt;a id="</span>navbarDropdown<span class="hljs-string">" class="</span>nav-link dropdown-toggle<span class="hljs-string">" href="</span><span class="hljs-comment">#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre&gt;</span>
                                    {{ Auth::user()-&gt;name }}
                                &lt;/a&gt;

                                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">dropdown</span>-<span class="hljs-title">menu</span> <span class="hljs-title">dropdown</span>-<span class="hljs-title">menu</span>-<span class="hljs-title">end</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">labelledby</span>="<span class="hljs-title">navbarDropdown</span>"&gt;
                                    &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">dropdown</span>-<span class="hljs-title">item</span>" <span class="hljs-title">href</span>="</span>{{ route(<span class="hljs-string">'logout'</span>) }}<span class="hljs-string">"
                                       onclick="</span>event.preventDefault();
                                                     document.getElementById(<span class="hljs-string">'logout-form'</span>).submit();<span class="hljs-string">"&gt;
                                        {{ __('Logout') }}
                                    &lt;/a&gt;

                                    &lt;form id="</span>logout-form<span class="hljs-string">" action="</span>{{ route(<span class="hljs-string">'logout'</span>) }}<span class="hljs-string">" method="</span>POST<span class="hljs-string">" class="</span>d-none<span class="hljs-string">"&gt;
                                        @csrf
                                    &lt;/form&gt;
                                &lt;/div&gt;
                            &lt;/li&gt;
                        @endguest
                    &lt;/ul&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/nav&gt;

        &lt;main class="</span>py<span class="hljs-number">-4</span><span class="hljs-string">"&gt;
            @yield('content')
        &lt;/main&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</span>
</code></pre>
<p>The complete Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/rDbsaA7bPMU">https://youtu.be/rDbsaA7bPMU</a></div>
<p>If you face any issues while making REST API, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/c/techtoolindia">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[How to use LARAVEL SANCTUM For API Authentication]]></title><description><![CDATA[Make REST API AUTHENTICATION in LARAVEL 9 USING LARAVEL SANCTUM
Laravel Sanctum provides a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token-based APIs.
Installation Steps
If you are not u...]]></description><link>https://techtoolindia.com/how-to-use-laravel-sanctum-for-api-authentication</link><guid isPermaLink="true">https://techtoolindia.com/how-to-use-laravel-sanctum-for-api-authentication</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Thu, 05 May 2022 13:55:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1651758753564/27G3iDF0z.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-make-rest-api-authentication-in-laravel-9-using-laravel-sanctum">Make REST API AUTHENTICATION in LARAVEL 9 USING LARAVEL SANCTUM</h2>
<p>Laravel Sanctum provides a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token-based APIs.</p>
<h2 id="heading-installation-steps">Installation Steps</h2>
<p>If you are not using LARAVEL 9 you need to install LARAVEL Sanctum Otherwise you can skip the installation step.</p>
<h3 id="heading-step-1">Step 1</h3>
<p>Install via composer</p>
<pre><code class="lang-php">composer <span class="hljs-keyword">require</span> laravel/sanctum
</code></pre>
<h3 id="heading-step-2">Step 2</h3>
<p>Publish the Sanctum Service Provider</p>
<pre><code class="lang-php">php artisan vendor:publish --provider=<span class="hljs-string">"Laravel\Sanctum\SanctumServiceProvider"</span>
</code></pre>
<h3 id="heading-step-3">Step 3</h3>
<p>Migrate The Database</p>
<pre><code class="lang-php">php artisan migrate
</code></pre>
<h2 id="heading-using-sanctum-in-laravel">USING SANCTUM IN LARAVEL</h2>
<h3 id="heading-user-hasapitokens-trait-in-appmodelsuser">User <code>HasApiTokens</code> Trait in <code>App\Models\User</code></h3>
<p>In Order to use Sanctum we need to use <code>HasApiTokens</code> Trait Class in User Model.
User Model should look like.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

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

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Contracts</span>\<span class="hljs-title">Auth</span>\<span class="hljs-title">MustVerifyEmail</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Factories</span>\<span class="hljs-title">HasFactory</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Foundation</span>\<span class="hljs-title">Auth</span>\<span class="hljs-title">User</span> <span class="hljs-title">as</span> <span class="hljs-title">Authenticatable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Notifications</span>\<span class="hljs-title">Notifiable</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Laravel</span>\<span class="hljs-title">Sanctum</span>\<span class="hljs-title">HasApiTokens</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Authenticatable</span>
</span>{
    <span class="hljs-keyword">use</span> <span class="hljs-title">HasApiTokens</span>, <span class="hljs-title">HasFactory</span>, <span class="hljs-title">Notifiable</span>;

    <span class="hljs-comment">/**
     * The attributes that are mass assignable.
     *
     * <span class="hljs-doctag">@var</span> array&lt;int, string&gt;
     */</span>
    <span class="hljs-keyword">protected</span> $fillable = [
        <span class="hljs-string">'name'</span>,
        <span class="hljs-string">'email'</span>,
        <span class="hljs-string">'password'</span>,
    ];

    <span class="hljs-comment">/**
     * The attributes that should be hidden for serialization.
     *
     * <span class="hljs-doctag">@var</span> array&lt;int, string&gt;
     */</span>
    <span class="hljs-keyword">protected</span> $hidden = [
        <span class="hljs-string">'password'</span>,
        <span class="hljs-string">'remember_token'</span>,
    ];

    <span class="hljs-comment">/**
     * The attributes that should be cast.
     *
     * <span class="hljs-doctag">@var</span> array&lt;string, string&gt;
     */</span>
    <span class="hljs-keyword">protected</span> $casts = [
        <span class="hljs-string">'email_verified_at'</span> =&gt; <span class="hljs-string">'datetime'</span>,
    ];
}
</code></pre>
<h3 id="heading-api-authentication-routes">API Authentication Routes</h3>
<p>Create <code>AuthController</code> to handle all authentication realted to API</p>
<pre><code class="lang-php">php artisan make:controller Api\\AuthController
</code></pre>
<p>In <code>routes\api.php</code> file update the API</p>
<pre><code class="lang-php">Route::post(<span class="hljs-string">'/auth/register'</span>, [AuthController::class, <span class="hljs-string">'createUser'</span>]);
Route::post(<span class="hljs-string">'/auth/login'</span>, [AuthController::class, <span class="hljs-string">'loginUser'</span>]);
</code></pre>
<p>Now update <code>AuthContoller</code> with</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Api</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Controller</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Auth</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Hash</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Validator</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AuthController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">/**
     * Create User
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> User 
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createUser</span>(<span class="hljs-params">Request $request</span>)
    </span>{
        <span class="hljs-keyword">try</span> {
            <span class="hljs-comment">//Validated</span>
            $validateUser = Validator::make($request-&gt;all(), 
            [
                <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'required'</span>,
                <span class="hljs-string">'email'</span> =&gt; <span class="hljs-string">'required|email|unique:users,email'</span>,
                <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'required'</span>
            ]);

            <span class="hljs-keyword">if</span>($validateUser-&gt;fails()){
                <span class="hljs-keyword">return</span> response()-&gt;json([
                    <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">false</span>,
                    <span class="hljs-string">'message'</span> =&gt; <span class="hljs-string">'validation error'</span>,
                    <span class="hljs-string">'errors'</span> =&gt; $validateUser-&gt;errors()
                ], <span class="hljs-number">401</span>);
            }

            $user = User::create([
                <span class="hljs-string">'name'</span> =&gt; $request-&gt;name,
                <span class="hljs-string">'email'</span> =&gt; $request-&gt;email,
                <span class="hljs-string">'password'</span> =&gt; Hash::make($request-&gt;password)
            ]);

            <span class="hljs-keyword">return</span> response()-&gt;json([
                <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">true</span>,
                <span class="hljs-string">'message'</span> =&gt; <span class="hljs-string">'User Created Successfully'</span>,
                <span class="hljs-string">'token'</span> =&gt; $user-&gt;createToken(<span class="hljs-string">"API TOKEN"</span>)-&gt;plainTextToken
            ], <span class="hljs-number">200</span>);

        } <span class="hljs-keyword">catch</span> (\<span class="hljs-built_in">Throwable</span> $th) {
            <span class="hljs-keyword">return</span> response()-&gt;json([
                <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">false</span>,
                <span class="hljs-string">'message'</span> =&gt; $th-&gt;getMessage()
            ], <span class="hljs-number">500</span>);
        }
    }

    <span class="hljs-comment">/**
     * Login The User
     * <span class="hljs-doctag">@param</span> Request $request
     * <span class="hljs-doctag">@return</span> User
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">loginUser</span>(<span class="hljs-params">Request $request</span>)
    </span>{
        <span class="hljs-keyword">try</span> {
            $validateUser = Validator::make($request-&gt;all(), 
            [
                <span class="hljs-string">'email'</span> =&gt; <span class="hljs-string">'required|email'</span>,
                <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'required'</span>
            ]);

            <span class="hljs-keyword">if</span>($validateUser-&gt;fails()){
                <span class="hljs-keyword">return</span> response()-&gt;json([
                    <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">false</span>,
                    <span class="hljs-string">'message'</span> =&gt; <span class="hljs-string">'validation error'</span>,
                    <span class="hljs-string">'errors'</span> =&gt; $validateUser-&gt;errors()
                ], <span class="hljs-number">401</span>);
            }

            <span class="hljs-keyword">if</span>(!Auth::attempt($request-&gt;only([<span class="hljs-string">'email'</span>, <span class="hljs-string">'password'</span>]))){
                <span class="hljs-keyword">return</span> response()-&gt;json([
                    <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">false</span>,
                    <span class="hljs-string">'message'</span> =&gt; <span class="hljs-string">'Email &amp; Password does not match with our record.'</span>,
                ], <span class="hljs-number">401</span>);
            }

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

            <span class="hljs-keyword">return</span> response()-&gt;json([
                <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">true</span>,
                <span class="hljs-string">'message'</span> =&gt; <span class="hljs-string">'User Logged In Successfully'</span>,
                <span class="hljs-string">'token'</span> =&gt; $user-&gt;createToken(<span class="hljs-string">"API TOKEN"</span>)-&gt;plainTextToken
            ], <span class="hljs-number">200</span>);

        } <span class="hljs-keyword">catch</span> (\<span class="hljs-built_in">Throwable</span> $th) {
            <span class="hljs-keyword">return</span> response()-&gt;json([
                <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">false</span>,
                <span class="hljs-string">'message'</span> =&gt; $th-&gt;getMessage()
            ], <span class="hljs-number">500</span>);
        }
    }
}
</code></pre>
<h3 id="heading-protect-api-with-authentication-we-need-to-use-authsanctum-middleware">Protect API With Authentication we need to use <code>auth:sanctum</code> middleware.</h3>
<pre><code class="lang-php">Route::apiResource(<span class="hljs-string">'posts'</span>, PostController::class)-&gt;middleware(<span class="hljs-string">'auth:sanctum'</span>);
</code></pre>
<p>Here are the results.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3payp41pzmr2lcuuuvx.png" alt="Register User" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/685yuqku1c8mz1xcaimc.png" alt="Login API" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/up6yc28lo9j3vccl5r7y.png" alt="GET API" /></p>
<p>The complete Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/GAB_BqFZNOA">https://youtu.be/GAB_BqFZNOA</a></div>
<p>If you face any issues while making REST API, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">TechToolIndia YouTube Channel</a></p>
]]></content:encoded></item><item><title><![CDATA[How to make REST API in LARAVEL 9]]></title><description><![CDATA[Make REST API in LARAVEL 9
Today I am going to explain how you can make REST API in Laravel 9. In this video, i am going to explain CRUD Operation using REST API.
Laravel 9 Installation.
After Installing Laravel 9 we will open the code in Editor.
Ste...]]></description><link>https://techtoolindia.com/how-to-make-rest-api-in-laravel-9</link><guid isPermaLink="true">https://techtoolindia.com/how-to-make-rest-api-in-laravel-9</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><category><![CDATA[REST API]]></category><category><![CDATA[APIs]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Wed, 30 Mar 2022 11:06:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1648638224088/Bw936yd6N.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-make-rest-api-in-laravel-9">Make REST API in LARAVEL 9</h2>
<p>Today I am going to explain how you can make REST API in Laravel 9. In this video, i am going to explain CRUD Operation using REST API.</p>
<h2 id="heading-laravel-9-installation">Laravel 9 Installation.</h2>
<p>After <a target="_blank" href="https://techtoolindia.com/how-to-install-laravel-9">Installing Laravel 9</a> we will open the code in Editor.</p>
<h2 id="heading-step-1">Step - 1</h2>
<p>Create a Model <code>Post</code> with migration.</p>
<pre><code class="lang-php">php artisan make:model Post -m
</code></pre>
<p>Next Update The Migration file at <code>database/migrations</code> folder.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Migrations</span>\<span class="hljs-title">Migration</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Schema</span>\<span class="hljs-title">Blueprint</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Schema</span>;

<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Migration</span>
</span>{
    <span class="hljs-comment">/**
     * Run the migrations.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)
    </span>{
        Schema::create(<span class="hljs-string">'posts'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Blueprint $table</span>) </span>{
            $table-&gt;id();
            $table-&gt;string(<span class="hljs-string">'title'</span>);
            $table-&gt;longText(<span class="hljs-string">'description'</span>);
            $table-&gt;timestamps();
        });
    }

    <span class="hljs-comment">/**
     * Reverse the migrations.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">down</span>(<span class="hljs-params"></span>)
    </span>{
        Schema::dropIfExists(<span class="hljs-string">'posts'</span>);
    }
};
</code></pre>
<p>Next update the Model fillable property in <code>app/models/Post.php</code></p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

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

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Factories</span>\<span class="hljs-title">HasFactory</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Post</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span>
</span>{
    <span class="hljs-keyword">use</span> <span class="hljs-title">HasFactory</span>;

    <span class="hljs-keyword">protected</span> $fillable = [<span class="hljs-string">'title'</span>, <span class="hljs-string">'description'</span>];
}
</code></pre>
<h2 id="heading-step-2">Step - 2</h2>
<p>Now Generate controller by running command</p>
<pre><code class="lang-php">php artisan make:controller Api\\PostController --model=Post
</code></pre>
<p>this command will generate the file in <code>app/Http/Controllers/Api/PostController.php</code></p>
<p>Open the file and update the code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Api</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Controller</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Requests</span>\<span class="hljs-title">StorePostRequest</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">Post</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PostController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">/**
     * Display a listing of the resource.
     *
     * <span class="hljs-doctag">@return</span> \Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>)
    </span>{
        $posts = Post::all();

        <span class="hljs-keyword">return</span> response()-&gt;json([
            <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">true</span>,
            <span class="hljs-string">'posts'</span> =&gt; $posts
        ]);
    }

    <span class="hljs-comment">/**
     * Show the form for creating a new resource.
     *
     * <span class="hljs-doctag">@return</span> \Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">create</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-comment">//</span>
    }

    <span class="hljs-comment">/**
     * Store a newly created resource in storage.
     *
     * <span class="hljs-doctag">@param</span>  \Illuminate\Http\Request  $request
     * <span class="hljs-doctag">@return</span> \Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">store</span>(<span class="hljs-params">StorePostRequest $request</span>)
    </span>{
        $post = Post::create($request-&gt;all());

        <span class="hljs-keyword">return</span> response()-&gt;json([
            <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">true</span>,
            <span class="hljs-string">'message'</span> =&gt; <span class="hljs-string">"Post Created successfully!"</span>,
            <span class="hljs-string">'post'</span> =&gt; $post
        ], <span class="hljs-number">200</span>);
    }

    <span class="hljs-comment">/**
     * Display the specified resource.
     *
     * <span class="hljs-doctag">@param</span>  \App\Models\Post  $post
     * <span class="hljs-doctag">@return</span> \Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">show</span>(<span class="hljs-params">Post $post</span>)
    </span>{
        <span class="hljs-comment">//</span>
    }

    <span class="hljs-comment">/**
     * Show the form for editing the specified resource.
     *
     * <span class="hljs-doctag">@param</span>  \App\Models\Post  $post
     * <span class="hljs-doctag">@return</span> \Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">edit</span>(<span class="hljs-params">Post $post</span>)
    </span>{
        <span class="hljs-comment">//</span>
    }

    <span class="hljs-comment">/**
     * Update the specified resource in storage.
     *
     * <span class="hljs-doctag">@param</span>  \Illuminate\Http\Request  $request
     * <span class="hljs-doctag">@param</span>  \App\Models\Post  $post
     * <span class="hljs-doctag">@return</span> \Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">update</span>(<span class="hljs-params">StorePostRequest $request, Post $post</span>)
    </span>{
        $post-&gt;update($request-&gt;all());

        <span class="hljs-keyword">return</span> response()-&gt;json([
            <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">true</span>,
            <span class="hljs-string">'message'</span> =&gt; <span class="hljs-string">"Post Updated successfully!"</span>,
            <span class="hljs-string">'post'</span> =&gt; $post
        ], <span class="hljs-number">200</span>);
    }

    <span class="hljs-comment">/**
     * Remove the specified resource from storage.
     *
     * <span class="hljs-doctag">@param</span>  \App\Models\Post  $post
     * <span class="hljs-doctag">@return</span> \Illuminate\Http\Response
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">destroy</span>(<span class="hljs-params">Post $post</span>)
    </span>{
        $post-&gt;delete();

        <span class="hljs-keyword">return</span> response()-&gt;json([
            <span class="hljs-string">'status'</span> =&gt; <span class="hljs-literal">true</span>,
            <span class="hljs-string">'message'</span> =&gt; <span class="hljs-string">"Post Deleted successfully!"</span>,
        ], <span class="hljs-number">200</span>);
    }
}
</code></pre>
<h2 id="heading-step-3">Step - 3</h2>
<p>Now Let's create the request to validate the data by running command below.</p>
<pre><code class="lang-php">php artisan make:request StorePostRequest
</code></pre>
<p>Now open file from <code>app/Http/Requests/StorePostRequest.php</code> and update the code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Requests</span>;

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

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StorePostRequest</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FormRequest</span>
</span>{
    <span class="hljs-comment">/**
     * Determine if the user is authorized to make this request.
     *
     * <span class="hljs-doctag">@return</span> bool
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">authorize</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }

    <span class="hljs-comment">/**
     * Get the validation rules that apply to the request.
     *
     * <span class="hljs-doctag">@return</span> array
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rules</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> [
            <span class="hljs-string">"title"</span> =&gt; <span class="hljs-string">"required|max:70"</span>,
            <span class="hljs-string">"description"</span> =&gt; <span class="hljs-string">"required"</span>
        ];
    }
}
</code></pre>
<h2 id="heading-step-4">Step - 4</h2>
<p>Now create the API routes in <code>routes/api.php</code> </p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PostController</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Route</span>;


Route::apiResource(<span class="hljs-string">'posts'</span>, PostController::class);
</code></pre>
<p>Now serve the application and open the URL in postman.
The results will look like.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8r3vfimiyhn7hk5loxw4.png" alt="Get POSTS" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zu9lvdy0u0c9at730t2j.png" alt="Store Post" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfxbjk1rvlo4u3znukct.png" alt="Update Post" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqkbxyxfmptkxojrjg95.png" alt="Delete Post" /></p>
<p>The complete Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/VKl9Kd2Moj8">https://youtu.be/VKl9Kd2Moj8</a></div>
<p>If you face any issues while making REST API, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">TechToolIndia YouTube Channel</a></p>
]]></content:encoded></item><item><title><![CDATA[How to send mail in laravel 9]]></title><description><![CDATA[Send MAIL In Laravel 9
Today I am going to explain how you can send MAIL using SMTP in Laravel 9.
Laravel UI Installation.
I have installed the laravel Now we will open the code in Editor.
Step - 1
Open .env file and change the MAIL Provider SMTP Det...]]></description><link>https://techtoolindia.com/how-to-send-mail-in-laravel-9</link><guid isPermaLink="true">https://techtoolindia.com/how-to-send-mail-in-laravel-9</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Laravel 5]]></category><category><![CDATA[laravel ]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Sun, 27 Mar 2022 11:55:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1648381850982/2DQPnNTAv.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-send-mail-in-laravel-9">Send MAIL In Laravel 9</h2>
<p>Today I am going to explain how you can send MAIL using SMTP in Laravel 9.</p>
<h2 id="heading-laravel-ui-installation">Laravel UI Installation.</h2>
<p>I have <a target="_blank" href="https://techtoolindia.com/how-to-install-laravel-9">installed the laravel</a> Now we will open the code in Editor.</p>
<h2 id="heading-step-1">Step - 1</h2>
<p>Open <code>.env</code> file and change the MAIL Provider SMTP Details</p>
<pre><code class="lang-php">MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=<span class="hljs-number">1025</span>
MAIL_USERNAME=<span class="hljs-literal">null</span>
MAIL_PASSWORD=<span class="hljs-literal">null</span>
MAIL_ENCRYPTION=<span class="hljs-literal">null</span>
</code></pre>
<p>You can use <a target="_blank" href="https://mailtrap.io/">MailTrap</a> to generate basic SMTP Details and test your email feature.</p>
<h2 id="heading-step-2">Step - 2</h2>
<p>Now Generate the email class by running the command</p>
<pre><code class="lang-php">php artisan make:mail TestEmail
</code></pre>
<p>this command will generate the file in <code>app/Mail/TestEmail.php</code></p>
<p>Open the file and update the code below.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

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

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

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

    <span class="hljs-keyword">public</span> $mailData;
    <span class="hljs-comment">/**
     * Create a new message instance.
     *
     * <span class="hljs-doctag">@return</span> void
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params">$mailData</span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;mailData = $mailData;
    }

    <span class="hljs-comment">/**
     * Build the message.
     *
     * <span class="hljs-doctag">@return</span> $this
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">build</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;subject(<span class="hljs-string">'Test Email'</span>)-&gt;view(<span class="hljs-string">'email.test'</span>);
    }
}
</code></pre>
<h2 id="heading-step-3">Step - 3</h2>
<p>Now Let's create a blade view file, for that let's create <code>email</code> folder first inside <code>resources/view</code>.</p>
<p>Now create a <code>test.blade.php</code> file inside email folder and paste the code below.</p>
<pre><code class="lang-php">&lt;!DOCTYPE html&gt;
&lt;html lang=<span class="hljs-string">"en"</span>&gt;
&lt;head&gt;
    &lt;meta charset=<span class="hljs-string">"UTF-8"</span>&gt;
    &lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;
    &lt;meta http-equiv=<span class="hljs-string">"X-UA-Compatible"</span> content=<span class="hljs-string">"ie=edge"</span>&gt;
    &lt;title&gt;Test Email&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;Test EMAIL&lt;/h1&gt;
    &lt;p&gt;Name: {{ $mailData[<span class="hljs-string">'name'</span>] }}&lt;/p&gt;
    &lt;p&gt;DOB: {{ $mailData[<span class="hljs-string">'dob'</span>] }}&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<h2 id="heading-step-4">Step - 4</h2>
<p>Now create a route to send email put the code below to <code>routes/web.php</code> </p>
<pre><code class="lang-php">
<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Mail</span>\<span class="hljs-title">TestEmail</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Mail</span>;

Route::get(<span class="hljs-string">'send-email'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    $mailData = [
        <span class="hljs-string">"name"</span> =&gt; <span class="hljs-string">"Test NAME"</span>,
        <span class="hljs-string">"dob"</span> =&gt; <span class="hljs-string">"12/12/1990"</span>
    ];

    Mail::to(<span class="hljs-string">"hello@example.com"</span>)-&gt;send(<span class="hljs-keyword">new</span> TestEmail($mailData));

    dd(<span class="hljs-string">"Mail Sent Successfully!"</span>);
});
</code></pre>
<p>Now visit to <code>/send-email</code> in the browser it should send the email to the inbox.</p>
<p>The Email Will look like.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7q6ngakjk6a3dy823emc.png" alt="EMAIl INBOX" /></p>
<p>The complete Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/WU4_HzTa6PM">https://youtu.be/WU4_HzTa6PM</a></div>
<p>If you face any issue while installing, please comment your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/shanisingh03">Twitter</a>
<a target="_blank" href="https://www.instagram.com/shanisingh03/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">TechToolIndia YouTube Channel</a></p>
]]></content:encoded></item><item><title><![CDATA[How To Change Password In Laravel 9]]></title><description><![CDATA[I am going to explain here, how you can change the password in laravel 9.
I have installed the laravel with Laravel Authentication and going to explain about changing the password of logged-in user.
Step 1 - Change Password Page:
Create a route for c...]]></description><link>https://techtoolindia.com/how-to-change-password-in-laravel-9</link><guid isPermaLink="true">https://techtoolindia.com/how-to-change-password-in-laravel-9</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Wed, 02 Mar 2022 21:57:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1646258022507/aRdYLSpcK.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I am going to explain here, how you can change the password in laravel 9.</p>
<p>I have <a target="_blank" href="https://techtoolindia.com/how-to-install-laravel-9">installed the laravel</a> with <a target="_blank" href="https://techtoolindia.com/how-to-make-login-and-register-in-laravel-9">Laravel Authentication</a> and going to explain about changing the password of logged-in user.</p>
<h2 id="heading-step-1-change-password-page">Step 1 - Change Password Page:</h2>
<h3 id="heading-create-a-route-for-change-password">Create a route for change password</h3>
<pre><code class="lang-php">Route::get(<span class="hljs-string">'/change-password'</span>, [App\Http\Controllers\HomeController::class, <span class="hljs-string">'changePassword'</span>])-&gt;name(<span class="hljs-string">'change-password'</span>);
</code></pre>
<h3 id="heading-cerate-changepassword-function-in-homecontroller">Cerate <code>changePassword</code> function in <code>HomeController</code></h3>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">changePassword</span>(<span class="hljs-params"></span>)
</span>{
   <span class="hljs-keyword">return</span> view(<span class="hljs-string">'change-password'</span>);
}
</code></pre>
<h3 id="heading-create-change-passwordbladephp-view-file-in-resourcesviews">Create <code>change-password.blade.php</code> view file in <code>resources/views</code></h3>
<pre><code class="lang-php">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'layouts.app'</span>)

@section(<span class="hljs-string">'content'</span>)
    &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">justify</span>-<span class="hljs-title">content</span>-<span class="hljs-title">center</span>"&gt;
            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-8"&gt;
                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;
                    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;</span>{{ __(<span class="hljs-string">'Chnage Password'</span>) }}&lt;/div&gt;

                    &lt;form action=<span class="hljs-string">"{{ route('update-password') }}"</span> method=<span class="hljs-string">"POST"</span>&gt;
                        @csrf
                        &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">body</span>"&gt;
                            @<span class="hljs-title">if</span> (<span class="hljs-title">session</span>('<span class="hljs-title">status</span>'))
                                &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">success</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"&gt;
                                    </span>{{ session(<span class="hljs-string">'status'</span>) }}
                                &lt;/div&gt;
                            @<span class="hljs-keyword">elseif</span> (session(<span class="hljs-string">'error'</span>))
                                &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">danger</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"&gt;
                                    </span>{{ session(<span class="hljs-string">'error'</span>) }}
                                &lt;/div&gt;
                            @<span class="hljs-keyword">endif</span>

                            &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">mb</span>-3"&gt;
                                &lt;<span class="hljs-title">label</span> <span class="hljs-title">for</span>="<span class="hljs-title">oldPasswordInput</span>" <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">label</span>"&gt;<span class="hljs-title">Old</span> <span class="hljs-title">Password</span>&lt;/<span class="hljs-title">label</span>&gt;
                                &lt;<span class="hljs-title">input</span> <span class="hljs-title">name</span>="<span class="hljs-title">old_password</span>" <span class="hljs-title">type</span>="<span class="hljs-title">password</span>" <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span> @<span class="hljs-title">error</span>('<span class="hljs-title">old_password</span>') <span class="hljs-title">is</span>-<span class="hljs-title">invalid</span> @<span class="hljs-title">enderror</span>" <span class="hljs-title">id</span>="<span class="hljs-title">oldPasswordInput</span>"
                                    <span class="hljs-title">placeholder</span>="<span class="hljs-title">Old</span> <span class="hljs-title">Password</span>"&gt;
                                @<span class="hljs-title">error</span>('<span class="hljs-title">old_password</span>')
                                    &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">text</span>-<span class="hljs-title">danger</span>"&gt;</span>{{ $message }}&lt;/span&gt;
                                @enderror
                            &lt;/div&gt;
                            &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">mb</span>-3"&gt;
                                &lt;<span class="hljs-title">label</span> <span class="hljs-title">for</span>="<span class="hljs-title">newPasswordInput</span>" <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">label</span>"&gt;<span class="hljs-title">New</span> <span class="hljs-title">Password</span>&lt;/<span class="hljs-title">label</span>&gt;
                                &lt;<span class="hljs-title">input</span> <span class="hljs-title">name</span>="<span class="hljs-title">new_password</span>" <span class="hljs-title">type</span>="<span class="hljs-title">password</span>" <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span> @<span class="hljs-title">error</span>('<span class="hljs-title">new_password</span>') <span class="hljs-title">is</span>-<span class="hljs-title">invalid</span> @<span class="hljs-title">enderror</span>" <span class="hljs-title">id</span>="<span class="hljs-title">newPasswordInput</span>"
                                    <span class="hljs-title">placeholder</span>="<span class="hljs-title">New</span> <span class="hljs-title">Password</span>"&gt;
                                @<span class="hljs-title">error</span>('<span class="hljs-title">new_password</span>')
                                    &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">text</span>-<span class="hljs-title">danger</span>"&gt;</span>{{ $message }}&lt;/span&gt;
                                @enderror
                            &lt;/div&gt;
                            &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">mb</span>-3"&gt;
                                &lt;<span class="hljs-title">label</span> <span class="hljs-title">for</span>="<span class="hljs-title">confirmNewPasswordInput</span>" <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">label</span>"&gt;<span class="hljs-title">Confirm</span> <span class="hljs-title">New</span> <span class="hljs-title">Password</span>&lt;/<span class="hljs-title">label</span>&gt;
                                &lt;<span class="hljs-title">input</span> <span class="hljs-title">name</span>="<span class="hljs-title">new_password_confirmation</span>" <span class="hljs-title">type</span>="<span class="hljs-title">password</span>" <span class="hljs-title">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">control</span>" <span class="hljs-title">id</span>="<span class="hljs-title">confirmNewPasswordInput</span>"
                                    <span class="hljs-title">placeholder</span>="<span class="hljs-title">Confirm</span> <span class="hljs-title">New</span> <span class="hljs-title">Password</span>"&gt;
                            &lt;/<span class="hljs-title">div</span>&gt;

                        &lt;/<span class="hljs-title">div</span>&gt;

                        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">footer</span>"&gt;
                            &lt;<span class="hljs-title">button</span> <span class="hljs-title">class</span>="<span class="hljs-title">btn</span> <span class="hljs-title">btn</span>-<span class="hljs-title">success</span>"&gt;<span class="hljs-title">Submit</span>&lt;/<span class="hljs-title">button</span>&gt;
                        &lt;/<span class="hljs-title">div</span>&gt;

                    &lt;/<span class="hljs-title">form</span>&gt;
                &lt;/<span class="hljs-title">div</span>&gt;
            &lt;/<span class="hljs-title">div</span>&gt;
        &lt;/<span class="hljs-title">div</span>&gt;
    &lt;/<span class="hljs-title">div</span>&gt;
@<span class="hljs-title">endsection</span></span>
</code></pre>
<p>The Output Will look like.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uajtxxmmr196e7o9aogk.png" alt="Change Password" /></p>
<h2 id="heading-step-2-handle-the-form-submit">Step 2 - Handle the Form Submit.</h2>
<h3 id="heading-create-a-post-route-in-routeswebphp-file">Create a POST route in <code>routes/web.php</code> file</h3>
<pre><code class="lang-php">Route::post(<span class="hljs-string">'/change-password'</span>, [App\Http\Controllers\HomeController::class, <span class="hljs-string">'updatePassword'</span>])-&gt;name(<span class="hljs-string">'update-password'</span>);
</code></pre>
<h3 id="heading-create-updatepassword-function-in-apphttpcontrollershomecontroller">Create <code>updatePassword</code> function in <code>app/Http/Controllers/HomeController</code>.</h3>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updatePassword</span>(<span class="hljs-params">Request $request</span>)
</span>{
        <span class="hljs-comment"># Validation</span>
        $request-&gt;validate([
            <span class="hljs-string">'old_password'</span> =&gt; <span class="hljs-string">'required'</span>,
            <span class="hljs-string">'new_password'</span> =&gt; <span class="hljs-string">'required|confirmed'</span>,
        ]);


        <span class="hljs-comment">#Match The Old Password</span>
        <span class="hljs-keyword">if</span>(!Hash::check($request-&gt;old_password, auth()-&gt;user()-&gt;password)){
            <span class="hljs-keyword">return</span> back()-&gt;with(<span class="hljs-string">"error"</span>, <span class="hljs-string">"Old Password Doesn't match!"</span>);
        }


        <span class="hljs-comment">#Update the new Password</span>
        User::whereId(auth()-&gt;user()-&gt;id)-&gt;update([
            <span class="hljs-string">'password'</span> =&gt; Hash::make($request-&gt;new_password)
        ]);

        <span class="hljs-keyword">return</span> back()-&gt;with(<span class="hljs-string">"status"</span>, <span class="hljs-string">"Password changed successfully!"</span>);
}
</code></pre>
<p>the final output will look like.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t8wc63n0ezhivttywy4x.png" alt="Change Password" /></p>
<p>The Complete Video Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/IM1bvPzJtTE">https://youtu.be/IM1bvPzJtTE</a></div>
<p>If you face any issues while implementing, please comment on your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">TechToolIndia YouTube Channel</a></p>
]]></content:encoded></item><item><title><![CDATA[How to make login and register in laravel 9]]></title><description><![CDATA[Make Login & Registration In Laravel 9
Today I am going to explain how you can generate Authentication scaffolding in Laravel 9.
Laravel UI Installation.
After Installing Laravel 9 we need to install laravel/ui package in order to generate authentica...]]></description><link>https://techtoolindia.com/how-to-make-login-and-register-in-laravel-9</link><guid isPermaLink="true">https://techtoolindia.com/how-to-make-login-and-register-in-laravel-9</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><category><![CDATA[login]]></category><category><![CDATA[Bootstrap]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Sat, 26 Feb 2022 10:36:20 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1645871340020/-aYmPzquP.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-make-login-andamp-registration-in-laravel-9">Make Login &amp; Registration In Laravel 9</h2>
<p>Today I am going to explain how you can generate Authentication scaffolding in Laravel 9.</p>
<h2 id="heading-laravel-ui-installation">Laravel UI Installation.</h2>
<p>After <a target="_blank" href="https://techtoolindia.com/how-to-install-laravel-9">Installing Laravel 9</a> we need to install <a target="_blank" href="https://github.com/laravel/ui">laravel/ui</a> package in order to generate authentication in laravel 9.</p>
<h2 id="heading-to-install-run-the-composer-command">To Install run the composer command</h2>
<pre><code class="lang-php">composer <span class="hljs-keyword">require</span> laravel/ui
</code></pre>
<h2 id="heading-after-composer-installation-run-artisan-command-to-generate-scaffolding">After Composer installation run artisan command to generate scaffolding.</h2>
<pre><code class="lang-php"><span class="hljs-comment">// Generate basic scaffolding...</span>
php artisan ui bootstrap
php artisan ui vue
php artisan ui react

<span class="hljs-comment">// Generate login / registration scaffolding...</span>
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth
</code></pre>
<p>After generating UI need to install npm dependencies.</p>
<pre><code class="lang-php">npm run install &amp;&amp; npm run dev
</code></pre>
<p>Next to Migrate the database</p>
<pre><code class="lang-php">php artisan migrate
</code></pre>
<h2 id="heading-the-output-will-look-like">The Output will look like.</h2>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8q1mtny08yk03qeqn7zu.png" alt="Laravel 9 Login Registration" /></p>
<p>The Installation Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/ul3t3YpTXM8">https://youtu.be/ul3t3YpTXM8</a></div>
<p>If you face any issue while installing, please comment your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">TechToolIndia YouTube Channel</a></p>
]]></content:encoded></item><item><title><![CDATA[How to install laravel 9]]></title><description><![CDATA[Install Laravel 9 In Local
Today I am going to explain how you can Install Laravel 9.
Laravel Installation Guide.
Laravel documented the Installation Guide you can read the document to get more details.
Tech Requirement

PHP 8.0.2
MySql
Composer

Ins...]]></description><link>https://techtoolindia.com/how-to-install-laravel-9</link><guid isPermaLink="true">https://techtoolindia.com/how-to-install-laravel-9</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Sat, 19 Feb 2022 07:28:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1645255545088/OJFzLJTIC.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-install-laravel-9-in-local">Install Laravel 9 In Local</h2>
<p>Today I am going to explain how you can Install Laravel 9.</p>
<h2 id="heading-laravel-installation-guide">Laravel Installation Guide.</h2>
<p>Laravel documented the <a target="_blank" href="https://laravel.com/docs/9.x#installation-via-composer">Installation Guide</a> you can read the document to get more details.</p>
<h2 id="heading-tech-requirement">Tech Requirement</h2>
<ul>
<li>PHP 8.0.2</li>
<li>MySql</li>
<li>Composer</li>
</ul>
<h2 id="heading-install-via-composer">Install Via Composer</h2>
<p>Create First Laravel 9 Project</p>
<pre><code class="lang-php">composer create-project laravel/laravel first-laravel9
</code></pre>
<p>Now GO to the Installed Directory</p>
<pre><code class="lang-php">cd first-laravel9
</code></pre>
<p>Next to serve the application </p>
<pre><code class="lang-php">php artisan serve
</code></pre>
<p>You can use <a target="_blank" href="https://laravel.com/docs/9.x/valet#main-content">Laravel Valet</a> to set up a local development environment in macOS.</p>
<p>All Set, Click on served Link and you can see the output as below.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k3mxkjwt121xwp0tn3ai.png" alt="Laravel 9" /> </p>
<p>The Installation Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/73PTcTSiIPw">https://youtu.be/73PTcTSiIPw</a></div>
<p>If you face any issues while installing, please comment with your query.</p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">TechToolIndia YouTube Channel</a></p>
]]></content:encoded></item><item><title><![CDATA[How to upgrade to laravel 9 from laravel 8]]></title><description><![CDATA[Upgrade to Laravel 9 from Laravel 8
Today I am going to explain how you can upgrade to Laravel 9 from Laravel 8.
Laravel Upgrade Guide.
Laravel documented the Upgrade Guide you can read for all upgrade steps.
Tech Admin Panel
I have Explained about c...]]></description><link>https://techtoolindia.com/how-to-upgrade-to-laravel-9-from-laravel-8</link><guid isPermaLink="true">https://techtoolindia.com/how-to-upgrade-to-laravel-9-from-laravel-8</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><category><![CDATA[PHP]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[Programming Tips]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Fri, 18 Feb 2022 07:58:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1645170839440/1Ft0MTDqx.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-upgrade-to-laravel-9-from-laravel-8">Upgrade to Laravel 9 from Laravel 8</h2>
<p>Today I am going to explain how you can upgrade to Laravel 9 from Laravel 8.</p>
<h2 id="heading-laravel-upgrade-guide">Laravel Upgrade Guide.</h2>
<p>Laravel documented the <a target="_blank" href="https://laravel.com/docs/9.x/upgrade#upgrade-9.0">Upgrade Guide</a> you can read for all upgrade steps.</p>
<h2 id="heading-tech-admin-panel">Tech Admin Panel</h2>
<p>I have Explained about creating Laravel Admin Panel (<a target="_blank" href="https://techtoolindia.hashnode.dev/how-to-create-admin-panel-in-laravel-8">Tech-Admin</a>) in Laravel 8.</p>
<p>Today In this Post I will explain how you can upgrade this to Laravel 9.</p>
<p>The Upgrade Tutorial is below in the video.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/zTB0qLChbAQ">https://youtu.be/zTB0qLChbAQ</a></div>
<p>In the Final Implementation <a target="_blank" href="https://github.com/TechTool-India/techtool-laravel-admin">Github Repository</a> you can download this and can use it for any project.</p>
<p>Some Final Output Screens are here</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53d53unbwjsvz2t0npan.png" alt="App Screenshot" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp9vfllktg4gyarwqq84.png" alt="App Screenshot" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijs2pn14sroqt37n6nq9.png" alt="App Screenshot" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5w9yy33y0fspnnl68t0m.png" alt="App Screenshot" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v5p71gck63r039mk6jix.png" alt="App Screenshot" /></p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">TechToolIndia YouTube Channel</a></p>
]]></content:encoded></item><item><title><![CDATA[How to export data to excel in Laravel 8]]></title><description><![CDATA[Export Data to Excel Files in Laravel 8
Today I am Going To Explain to you how you can Export Excel  Files in Laravel 8.
I am going to use Tech-Admin Panel for this.
For Exporting an excel file I am using Laravel Excel.
You can read about 
Laravel Im...]]></description><link>https://techtoolindia.com/how-to-export-data-to-excel-in-laravel-8</link><guid isPermaLink="true">https://techtoolindia.com/how-to-export-data-to-excel-in-laravel-8</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><category><![CDATA[PHP]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Tue, 15 Feb 2022 11:36:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1644924607630/qGQCMowQQ.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/whzmfut4kqf1rg88v0e3.png" alt="Export Laravel Excel" /></p>
<h2 id="heading-export-data-to-excel-files-in-laravel-8">Export Data to Excel Files in Laravel 8</h2>
<p>Today I am Going To Explain to you how you can Export Excel  Files in Laravel 8.</p>
<p>I am going to use <a target="_blank" href="https://techtoolindia.hashnode.dev/how-to-create-admin-panel-in-laravel-8">Tech-Admin Panel</a> for this.</p>
<p>For Exporting an excel file I am using <a target="_blank" href="https://laravel-excel.com/">Laravel Excel</a>.</p>
<p>You can read about 
<a target="_blank" href="https://techtoolindia.hashnode.dev/how-to-import-excel-csv-files-into-laravel-8">Laravel Import From CSV/ Excel Files Here!</a></p>
<h2 id="heading-step-1-installation">Step 1 - Installation</h2>
<p>To Install the <a target="_blank" href="https://laravel-excel.com/">Laravel Excel</a> Package via composer run command below.</p>
<pre><code class="lang-php">composer <span class="hljs-keyword">require</span> maatwebsite/excel
</code></pre>
<p>Next to export config file you need run command below.</p>
<pre><code class="lang-php">php artisan vendor:publish --provider=<span class="hljs-string">"Maatwebsite\Excel\ExcelServiceProvider"</span> --tag=config
</code></pre>
<h2 id="heading-step-2-create-an-exports-class-inside-appexports">Step 2 - Create an Exports Class inside <code>app/Exports</code></h2>
<p>Create Exports Class by using artisan command</p>
<pre><code class="lang-php">php artisan make:export UsersExport --model=User
</code></pre>
<h2 id="heading-step-3-handle-export-to-excel-function">Step 3 - Handle Export To Excel Function</h2>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">export</span>(<span class="hljs-params"></span>) 
</span>{
   <span class="hljs-keyword">return</span> Excel::download(<span class="hljs-keyword">new</span> UsersExport, <span class="hljs-string">'users.xlsx'</span>);
}
</code></pre>
<p>You can watch the explanation video for more clarity.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=_tRwyCCQ9dQ">https://www.youtube.com/watch?v=_tRwyCCQ9dQ</a></div>
<p>Thank You for Reading</p>
<p>In case of any query related to LARAVEL.</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[How to import excel CSV files into Laravel 8]]></title><description><![CDATA[Import CSV Files into Laravel 8
Today I am Going To Explain to you how you can import Excel / CSV Files into Laravel.
I am going to use Tech-Admin Panel for this.
For importing excel files i am using Laravel Excel.
Step 1 - Installation
To Install th...]]></description><link>https://techtoolindia.com/how-to-import-excel-csv-files-into-laravel-8</link><guid isPermaLink="true">https://techtoolindia.com/how-to-import-excel-csv-files-into-laravel-8</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel ]]></category><category><![CDATA[excel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Sat, 12 Feb 2022 11:03:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1644663449106/cvGJZIRX5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bd4a4oxd7v7b0j8qer17.png" alt="Import Laravel Excel" /></p>
<h2 id="heading-import-csv-files-into-laravel-8">Import CSV Files into Laravel 8</h2>
<p>Today I am Going To Explain to you how you can import Excel / CSV Files into Laravel.</p>
<p>I am going to use <a target="_blank" href="https://dev.to/techtoolindia/how-to-create-admin-panel-in-laravel-8-in-10-min-43ni">Tech-Admin Panel</a> for this.</p>
<p>For importing excel files i am using <a target="_blank" href="https://laravel-excel.com/">Laravel Excel</a>.</p>
<h2 id="heading-step-1-installation">Step 1 - Installation</h2>
<p>To Install the <a target="_blank" href="https://laravel-excel.com/">Laravel Excel</a> Package via composer run command below.</p>
<pre><code class="lang-php">composer <span class="hljs-keyword">require</span> maatwebsite/excel
</code></pre>
<p>Next to export config file you need run command below.</p>
<pre><code class="lang-php">php artisan vendor:publish --provider=<span class="hljs-string">"Maatwebsite\Excel\ExcelServiceProvider"</span> --tag=config
</code></pre>
<h2 id="heading-step-2-create-an-import-class-inside-appimports">Step 2 - Create an Import Class inside <code>app/Imports</code></h2>
<p>Create Import Class by using artisan command</p>
<pre><code class="lang-php">php artisan make:import UsersImport --model=User
</code></pre>
<h2 id="heading-step-3-update-usersimport-class">Step 3 - Update UsersImport Class</h2>
<p>In order use CSV/Excel Files with heading we have to implement <code>WithHeadingRow</code>, UsersImport Class will look like.</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

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

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Models</span>\<span class="hljs-title">User</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">DB</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Hash</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Maatwebsite</span>\<span class="hljs-title">Excel</span>\<span class="hljs-title">Concerns</span>\<span class="hljs-title">ToModel</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Maatwebsite</span>\<span class="hljs-title">Excel</span>\<span class="hljs-title">Concerns</span>\<span class="hljs-title">WithHeadingRow</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UsersImport</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ToModel</span>, <span class="hljs-title">WithHeadingRow</span>
</span>{
    <span class="hljs-comment">/**
    * <span class="hljs-doctag">@param</span> array $row
    *
    * <span class="hljs-doctag">@return</span> \Illuminate\Database\Eloquent\Model|null
    */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">model</span>(<span class="hljs-params"><span class="hljs-keyword">array</span> $row</span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> User([
            <span class="hljs-string">"first_name"</span> =&gt; $row[<span class="hljs-string">'first_name'</span>],
            <span class="hljs-string">"last_name"</span> =&gt; $row[<span class="hljs-string">'last_name'</span>],
            <span class="hljs-string">"email"</span> =&gt; $row[<span class="hljs-string">'email'</span>],
            <span class="hljs-string">"mobile_number"</span> =&gt; $row[<span class="hljs-string">'mobile_number'</span>],
            <span class="hljs-string">"role_id"</span> =&gt; <span class="hljs-number">2</span>, <span class="hljs-comment">// User Type User</span>
            <span class="hljs-string">"status"</span> =&gt; <span class="hljs-number">1</span>,
            <span class="hljs-string">"password"</span> =&gt; Hash::make(<span class="hljs-string">'password'</span>)
        ]);
    }
}
</code></pre>
<h2 id="heading-step-4-handle-uploaded-excelcsv-file">Step 4 - Handle Uploaded Excel/CSV File</h2>
<pre><code class="lang-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">uploadUsers</span>(<span class="hljs-params">Request $request</span>)
</span>{
        Excel::import(<span class="hljs-keyword">new</span> UsersImport, $request-&gt;file);

        <span class="hljs-keyword">return</span> redirect()-&gt;route(<span class="hljs-string">'users.index'</span>)-&gt;with(<span class="hljs-string">'success'</span>, <span class="hljs-string">'User Imported Successfully'</span>);
}
</code></pre>
<p>You can watch the explanation video for more clarity.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=-h2wpwATsXw">https://www.youtube.com/watch?v=-h2wpwATsXw</a></div>
<p>In Next part i will explain about Export Users.</p>
<p>Thank You for Reading!</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/techtoolindia">Twitter</a>
<a target="_blank" href="https://www.instagram.com/techtoolindia/">Instagram</a>
<a target="_blank" href="https://www.youtube.com/channel/UCOy6o08Yn9DtXMKqxhD9ivA">YouTube</a></p>
]]></content:encoded></item><item><title><![CDATA[How to create Admin Panel in LARAVEL 8?]]></title><description><![CDATA[Tech-Admin - Laravel 8 Admin Starter Kit
Today I am going to explain about installing LARAVEL 8 admin starter kit.
Features

Mobile Responsive Bootstrap 4 Design
User Management with Roles
Role Management
Permissions Management
Access Control List (A...]]></description><link>https://techtoolindia.com/how-to-create-admin-panel-in-laravel-8</link><guid isPermaLink="true">https://techtoolindia.com/how-to-create-admin-panel-in-laravel-8</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[PHP]]></category><dc:creator><![CDATA[Shani Singh]]></dc:creator><pubDate>Mon, 31 Jan 2022 13:52:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1643636791824/xythAq9KC.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53d53unbwjsvz2t0npan.png" alt="Alt Text" /></p>
<h2 id="heading-tech-admin-laravel-8-admin-starter-kit">Tech-Admin - Laravel 8 Admin Starter Kit</h2>
<p>Today I am going to explain about installing LARAVEL 8 admin starter kit.</p>
<h2 id="heading-features">Features</h2>
<ul>
<li>Mobile Responsive Bootstrap 4 Design</li>
<li>User Management with Roles</li>
<li>Role Management</li>
<li>Permissions Management</li>
<li>Access Control List (ACL)</li>
<li>Laravel 8 + Bootstrap 4</li>
</ul>
<p>I have Explained every step in this video you can watch and try this out, </p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=AQeWj89c6FE">https://www.youtube.com/watch?v=AQeWj89c6FE</a></div>
<p>In the Final Implementation <a target="_blank" href="https://github.com/TechTool-India/techtool-laravel-admin">Github Repository</a> you can download this and can use it for any project.</p>
<p>Some Final Output Screens are here</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53d53unbwjsvz2t0npan.png" alt="App Screenshot" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp9vfllktg4gyarwqq84.png" alt="App Screenshot" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijs2pn14sroqt37n6nq9.png" alt="App Screenshot" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5w9yy33y0fspnnl68t0m.png" alt="App Screenshot" /></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v5p71gck63r039mk6jix.png" alt="App Screenshot" /></p>
<p>Thank You for Reading</p>
<p>Reach Out To me.
<a target="_blank" href="https://twitter.com/shanisingh03">Twitter</a>
<a target="_blank" href="https://www.instagram.com/shanisingh03/">Instagram</a>
<a target="_blank" href="https://youtube.com/techtoolindia">TechToolIndia</a></p>
]]></content:encoded></item></channel></rss>