<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Povilas Korop</title>
    <description>The latest articles on DEV Community by Povilas Korop (@povilaskorop).</description>
    <link>https://dev.to/povilaskorop</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F109258%2Fd50118a2-9f4d-4473-a504-cd4b0479becf.jpg</url>
      <title>DEV Community: Povilas Korop</title>
      <link>https://dev.to/povilaskorop</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/povilaskorop"/>
    <language>en</language>
    <item>
      <title>How (NOT) to Argue Online - 8 Tips from Taylor Otwell</title>
      <dc:creator>Povilas Korop</dc:creator>
      <pubDate>Wed, 27 Oct 2021 05:08:44 +0000</pubDate>
      <link>https://dev.to/povilaskorop/how-not-to-argue-online-8-tips-from-taylor-otwell-4ik3</link>
      <guid>https://dev.to/povilaskorop/how-not-to-argue-online-8-tips-from-taylor-otwell-4ik3</guid>
      <description>&lt;p&gt;These days, arguing between developers about some framework or pattern became a norm. But quite often, those arguments become very negative, turning into toxic personal attacks, just because someone likes X way over Y way of coding things. How can we make it better?&lt;/p&gt;

&lt;p&gt;I've found a ton of answers in a great podcast episode called &lt;a href="https://www.thingsworthlearning.show/episodes/being-open-minded-in-tech-and-everywhere-else-with-taylor-otwell"&gt;Being Open Minded In Tech And Everywhere Else, with Taylor Otwell&lt;/a&gt;, recorded as a part of &lt;a href="https://twitter.com/stauffermatt?lang=en"&gt;Matt Stauffer's&lt;/a&gt; podcast &lt;a href="https://www.thingsworthlearning.show/"&gt;Things Worth Learning&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Taylor's and Matt's thoughts on how to process the arguments online are so fundamental that I decided to summarize them in a form of this short article.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tip 1. Be open-minded and don't get defensive
&lt;/h2&gt;

&lt;p&gt;If you prefer to do things some way, it doesn't mean it's the only way. Quite often, there are different ways, which may be very logical from the other developer's point of view.&lt;/p&gt;

&lt;p&gt;So, if you get into argument on, say, Twitter, start from yourself. Assume that there MAY be another "alternate reality", you are just not familiar with it.&lt;/p&gt;

&lt;p&gt;It's perfectly normal to ask:&lt;br&gt;
&lt;em&gt;"I don't fully understand the case, please explain to me why you think that way"&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Don't be afraid to look stupid, it's actually your chance to learn something meaningful.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tip 2. Look at the code
&lt;/h2&gt;

&lt;p&gt;So many coding arguments happen about theoretical concepts, philosophies and coding patterns - without anyone actually looking at code examples.&lt;/p&gt;

&lt;p&gt;It's not easy to fit a code example in 280 characters on Twitter, but there are Github/Gists for this. It's so much more useful and productive to analyze the specific example, which may clarify why some person is right, or misunderstood the situation.&lt;/p&gt;

&lt;p&gt;Now, this tip requires real &lt;strong&gt;effort&lt;/strong&gt; to get out of social media, find/create the example and share it. But that's kind of the point: quick theoretical idea that "I don't like X" is easy to make, whereas a productive discussion does require effort on both sides.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tip 3. Assume good intentions
&lt;/h2&gt;

&lt;p&gt;When reading posts online, it's so easy to misunderstand the tone of the person behind the post. There are often "grey areas" in how you can interpret the intention.&lt;/p&gt;

&lt;p&gt;That's why Taylor suggests to always assume that the post author has good intentions: from his experience, he wants to improve something in the world. &lt;/p&gt;

&lt;p&gt;Of course, during the argument, it may appear that the person is actually just a troll who wants to ruin you in some way, but here's where we come to the next tip...&lt;/p&gt;




&lt;h2&gt;
  
  
  Tip 4. Some people just want to be heard
&lt;/h2&gt;

&lt;p&gt;You can imagine how many requests Taylor has been getting over 10 years of Laravel. A lot of people advise that Taylor should do this or that in a different way.&lt;/p&gt;

&lt;p&gt;In many cases, however, it's just enough to reply with some form of &lt;em&gt;"Thank you, it's a valid concern, I'll keep that in mind"&lt;/em&gt; and just move on, proceeding with the way how YOU think is best for the consumers/customers of your software. &lt;/p&gt;

&lt;p&gt;What happens then? The person should feel &lt;strong&gt;heard&lt;/strong&gt;, and that often is what they came for. Some people just need the approval that their idea is understood, not necessarily accepted. &lt;/p&gt;

&lt;p&gt;Quite often, one sentence response is enough to show attention.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tip 5. Will your words benefit them?
&lt;/h2&gt;

&lt;p&gt;Just like you need to assume good intentions from other people, you need to have them yourself. When thinking how to reply to the argument, think if your message will actually HELP that person.&lt;/p&gt;

&lt;p&gt;Two things here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is it worth replying at all? Can you actually benefit or help that person?&lt;/li&gt;
&lt;li&gt;If you reply, phrase the message in a way that would actually improve the situation for them&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Even if you disagree, the tone of your message is &lt;strong&gt;extremely&lt;/strong&gt; important. &lt;/p&gt;

&lt;p&gt;I personally had issues with it in the past, coming across as too harsh when "attacking the new ways of coding", although my intentions were to defend some other group of developers who were used to "the old way". &lt;/p&gt;




&lt;h2&gt;
  
  
  Tip 6. Come at your best state of mind
&lt;/h2&gt;

&lt;p&gt;There was a phrase in the podcast that was like a "by the way" thing, but it struck me.&lt;/p&gt;

&lt;p&gt;Taylor said: &lt;em&gt;"If I come online in my best state of mind, I tend to..."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yes, yes, 100x yes.&lt;/p&gt;

&lt;p&gt;Don't come online to argue if you're not in the mood. You may ruin relationships easily this way.&lt;/p&gt;

&lt;p&gt;Try to reply to posts and messages only when you have clear mind and not affected by a bad day, or some other factors.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tip 7. Build friendships, then argue
&lt;/h2&gt;

&lt;p&gt;It's 100x easier to say someone is wrong if you don't know that person. Well, that's what social media is about: nameless people with animated avatars are often attacking real people, hiding behind pseudonyms.&lt;/p&gt;

&lt;p&gt;But if you build some relationship with people, then you can discuss issues more openly and go a bit deeper. You will also likely have more context on WHY they do it that way, their size of company, projects etc.&lt;/p&gt;

&lt;p&gt;In other words, don't argue with nameless people, they are much more likely to be trolling you. &lt;/p&gt;




&lt;h2&gt;
  
  
  Tip 8. In general, stop arguing
&lt;/h2&gt;

&lt;p&gt;This final thought comes from a classic book &lt;a href="https://www.amazon.com/How-Win-Friends-Influence-People/dp/0671027034"&gt;How to Win Friends in Influence People&lt;/a&gt; by Dale Carnegie. &lt;/p&gt;

&lt;p&gt;Taylor mentioned the idea from this book: you just don't win at arguments. Ever. You lose either way. &lt;/p&gt;

&lt;p&gt;If you win the argument, then your opponent probably feels bad, and you lose by ruing their well-being. And if you lose the argument, well, you lose.&lt;/p&gt;

&lt;p&gt;So it's &lt;strong&gt;not even logical&lt;/strong&gt; to have deeper and longer arguments, whether it's online or offline. &lt;/p&gt;




&lt;p&gt;So, next time, if your idea is "attacked" online, come to reply at your best state of mind, with good intentions, and not with the goal of arguing. &lt;/p&gt;

&lt;p&gt;This way, you may learn something new and find new friends.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Laravel: Approve New Registered Users from Administrator</title>
      <dc:creator>Povilas Korop</dc:creator>
      <pubDate>Mon, 22 Oct 2018 08:24:45 +0000</pubDate>
      <link>https://dev.to/povilaskorop/laravel-approve-new-registered-users-from-administrator-3nbh</link>
      <guid>https://dev.to/povilaskorop/laravel-approve-new-registered-users-from-administrator-3nbh</guid>
      <description>&lt;p&gt;Laravel framework comes with built-in Auth system, which is pretty good. But it doesn't cover all the cases, and the most common one is administrator approval of every new registered user. In this article, I will show you how to do it in fresh Laravel 5.7 project.&lt;/p&gt;

&lt;p&gt;What we will cover:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Preparing DB structure: migrations, models and seeders&lt;/li&gt;
&lt;li&gt;Restricting new users from accessing dashboard&lt;/li&gt;
&lt;li&gt;Notifying administrator about new user&lt;/li&gt;
&lt;li&gt;Approving new user by administrator&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;First, let's create a new Laravel project:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Then you need to configure our &lt;strong&gt;.env&lt;/strong&gt; file with database credentials. &lt;/p&gt;

&lt;p&gt;Next, let's generate our Login/Register links:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:auth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we can log in with this form:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4i3lro7rak4jai7ws42.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4i3lro7rak4jai7ws42.png" alt="Laravel login auth" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From &lt;code&gt;users&lt;/code&gt; DB table perspective, we need to add two fields: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;admin&lt;/code&gt; (boolean, 0/1) - you may have more complicated logic with roles/permissions&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;approved_at&lt;/code&gt; (timestamp, nullable) - will be set to current timestamp when approved&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:migration add_admin_to_users_table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then the migration itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Schema::table('users', function (Blueprint $table) {
    $table-&amp;gt;boolean('admin')-&amp;gt;default(false);
    $table-&amp;gt;timestamp('approved_at')-&amp;gt;nullable();
});

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

&lt;/div&gt;



&lt;p&gt;Also, we need to add those fields into &lt;code&gt;$fillable&lt;/code&gt; array in &lt;code&gt;app/User.php&lt;/code&gt; model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected $fillable = [
    'name', 'email', 'password', 'admin', 'approved_at'
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Seeding admin user
&lt;/h2&gt;

&lt;p&gt;This command will help us:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:seeder AdminSeeder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will generate a new file in &lt;code&gt;database/seeds&lt;/code&gt; folder, which we fill like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class AdminSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        \App\User::create([
            'name' =&amp;gt; 'Admin',
            'email' =&amp;gt; 'admin@admin.com',
            'email_verified_at' =&amp;gt; now(),
            'password' =&amp;gt; bcrypt('verysafepassword'),
            'admin' =&amp;gt; 1,
            'approved_at' =&amp;gt; now(),
        ]);
    }
}

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

&lt;/div&gt;



&lt;p&gt;Finally, we need to add this class to the main &lt;code&gt;database/seeds/DatabaseSeeder.php&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function run()
{
    $this-&amp;gt;call(AdminSeeder::class);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we're ready with our DB structure and can run this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan migrate --seed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, if we log in with credentials &lt;code&gt;admin@admin.com&lt;/code&gt; - &lt;code&gt;verysafepassword&lt;/code&gt;, we should see our empty Home Dashboard, from default Laravel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgkns54ka5uiz5rq3f7cl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgkns54ka5uiz5rq3f7cl.png" alt="Laravel auth home dashboard" width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Restricting New User from Dashboard
&lt;/h2&gt;

&lt;p&gt;Ok, now we can register with new user which will be not approved. Let's restrict them from accessing the actual dashboard.&lt;/p&gt;

&lt;p&gt;First, we create a separate Blade file which will have text like "Waiting for approval". This will be a page we will redirect to, for every request of non-approved user.&lt;/p&gt;

&lt;p&gt;So, &lt;code&gt;resources/views/approval.blade.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

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

@section('content')
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;div class="row justify-content-center"&amp;gt;
            &amp;lt;div class="col-md-8"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-header"&amp;gt;Waiting for Approval&amp;lt;/div&amp;gt;

                    &amp;lt;div class="card-body"&amp;gt;
                        Your account is waiting for our administrator approval.
                        &amp;lt;br /&amp;gt;
                        Please check back later.
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
@endsection

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

&lt;/div&gt;



&lt;p&gt;Next, we create a Controller to point to it. Or, in fact, we create a method in the same &lt;code&gt;HomeController&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function approval()
{
    return view('approval');
}

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

&lt;/div&gt;



&lt;p&gt;Here's how it looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkqgcpe3y0lnejxdpqzm9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkqgcpe3y0lnejxdpqzm9.png" alt="Laravel user approve" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, we need a &lt;strong&gt;route&lt;/strong&gt; for it. Let's put it under &lt;code&gt;auth&lt;/code&gt; middleware, and our &lt;code&gt;routes/web.php&lt;/code&gt; will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::middleware(['auth'])-&amp;gt;group(function () {
    Route::get('/approval', 'HomeController@approval')-&amp;gt;name('approval');
    Route::get('/home', 'HomeController@index')-&amp;gt;name('home');
});

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

&lt;/div&gt;



&lt;p&gt;Now, we need to restrict the access for non-approved users to that &lt;code&gt;/home&lt;/code&gt; URL. We create a new &lt;strong&gt;Middleware&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:middleware CheckApproved
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It generates a file &lt;code&gt;app/Http/Middleware/CheckApproved.php&lt;/code&gt; which we fill like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace App\Http\Middleware;

use Closure;

class CheckApproved
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!auth()-&amp;gt;user()-&amp;gt;approved_at) {
            return redirect()-&amp;gt;route('approval');
        }

        return $next($request);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to register that Middleware in &lt;code&gt;app/Http/Kernel.php&lt;/code&gt; in the &lt;code&gt;$routeMiddleware&lt;/code&gt; array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected $routeMiddleware = [
    'auth' =&amp;gt; \App\Http\Middleware\Authenticate::class,
    // ...
    'verified' =&amp;gt; \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
    'approved' =&amp;gt; \App\Http\Middleware\CheckApproved::class,
];

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

&lt;/div&gt;



&lt;p&gt;Finally, we add the &lt;code&gt;home&lt;/code&gt; route to the block under that Middleware, so our &lt;code&gt;routes/web.php&lt;/code&gt; now looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::middleware(['auth'])-&amp;gt;group(function () {
    Route::get('/approval', 'HomeController@approval')-&amp;gt;name('approval');

    Route::middleware(['approved'])-&amp;gt;group(function () {
        Route::get('/home', 'HomeController@index')-&amp;gt;name('home');
    });
});

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

&lt;/div&gt;



&lt;p&gt;So now, every new user, after logging in, or on any action, will be redirected to the &lt;code&gt;approval page&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Notifying Administrator About New User
&lt;/h2&gt;

&lt;p&gt;We will use &lt;a href="https://laravel.com/docs/5.7/notifications" rel="noopener noreferrer"&gt;Laravel Notifications&lt;/a&gt; function that comes with the framework.&lt;/p&gt;

&lt;p&gt;Let's generate a new Notification class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:notification NewUser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we fill in a newly generated &lt;code&gt;app/Notifications/NewUser.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace App\Notifications;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class NewUser extends Notification
{
    use Queueable;

    private $new_user;

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


    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            -&amp;gt;line('New user has registered with email ' . $this-&amp;gt;new_user-&amp;gt;email)
            -&amp;gt;action('Approve user', route('admin.users.approve', $this-&amp;gt;new_user-&amp;gt;id));
    }

}

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

&lt;/div&gt;



&lt;p&gt;A few things to notice here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We will pass new registered user as an object via &lt;code&gt;__construct()&lt;/code&gt; method, then it turns into a local private variable, which we will use in &lt;code&gt;toMail()&lt;/code&gt; method as &lt;code&gt;$this-&amp;gt;new_user&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;We specify the route to approve user, and we will create the functionality a little later below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, to use this Notification, we will extend a controller &lt;code&gt;app/Http/Controllers/Auth/RegisterController.php&lt;/code&gt;, specifically method &lt;code&gt;create()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Don't forget to add this
use App\Notifications\NewUser;

// ...

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    $user = User::create([
        'name' =&amp;gt; $data['name'],
        'email' =&amp;gt; $data['email'],
        'password' =&amp;gt; Hash::make($data['password']),
    ]);

    $admin = User::where('admin', 1)-&amp;gt;first();
    if ($admin) {
        $admin-&amp;gt;notify(new NewUser($user));
    }

    return $user;
}

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

&lt;/div&gt;



&lt;p&gt;To test sending of an email, I recommend &lt;a href="https://mailtrap.io/" rel="noopener noreferrer"&gt;MailTrap&lt;/a&gt; which I will use and put its credentials to Laravel &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=54043xxxxxxxxxx
MAIL_PASSWORD=a7d17xxxxxxxxx
MAIL_ENCRYPTION=null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, on every new user, admin will get something like this:&lt;/p&gt;

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




&lt;h2&gt;
  
  
  Approving New User by Administrator
&lt;/h2&gt;

&lt;p&gt;In previous step, we've used a route: &lt;code&gt;route('admin.users.approve', $this-&amp;gt;new_user-&amp;gt;id)&lt;/code&gt;, now let's actually implement it.&lt;/p&gt;

&lt;p&gt;We actually need two routes: to list the users, and to approve one of them.&lt;br&gt;
Also, we need to restrict it for admin users only, so let's generate another middleware:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:middleware CheckAdmin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We fill the new file &lt;code&gt;app/Http/Middleware/CheckAdmin.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace App\Http\Middleware;

use Closure;

class CheckAdmin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!auth()-&amp;gt;user()-&amp;gt;admin) {
            return redirect()-&amp;gt;route('home');
        }

        return $next($request);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need to add it to &lt;code&gt;app/Http/Kernel.php&lt;/code&gt; array, as above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected $routeMiddleware = [
    'auth' =&amp;gt; \App\Http\Middleware\Authenticate::class,
    // ...
    'approved' =&amp;gt; \App\Http\Middleware\CheckApproved::class,
    'admin' =&amp;gt; \App\Http\Middleware\CheckAdmin::class,
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, here's our final &lt;code&gt;routes/web.php&lt;/code&gt; version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::middleware(['auth'])-&amp;gt;group(function () {
    Route::get('/approval', 'HomeController@approval')-&amp;gt;name('approval');

    Route::middleware(['approved'])-&amp;gt;group(function () {
        Route::get('/home', 'HomeController@index')-&amp;gt;name('home');
    });

    Route::middleware(['admin'])-&amp;gt;group(function () {
        Route::get('/users', 'UserController@index')-&amp;gt;name('admin.users.index');
        Route::get('/users/{user_id}/approve', 'UserController@approve')-&amp;gt;name('admin.users.approve');
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Last thing we need is to implement the actual approval.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:controller UserController
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's the code for &lt;code&gt;app/Http/Controllers/UserController.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace App\Http\Controllers;

use App\User;

class UserController extends Controller
{

    public function index()
    {
        $users = User::whereNull('approved_at')-&amp;gt;get();

        return view('users', compact('users'));
    }

    public function approve($user_id)
    {
        $user = User::findOrFail($user_id);
        $user-&amp;gt;update(['approved_at' =&amp;gt; now()]);

        return redirect()-&amp;gt;route('admin.users.index')-&amp;gt;withMessage('User approved successfully');
    }

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

&lt;/div&gt;



&lt;p&gt;So method &lt;code&gt;approve()&lt;/code&gt; will approve user and redirect back to the list. Which is implemented in &lt;code&gt;resources/views/users.blade.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

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

@section('content')
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;div class="row justify-content-center"&amp;gt;
            &amp;lt;div class="col-md-8"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-header"&amp;gt;Users List to Approve&amp;lt;/div&amp;gt;

                    &amp;lt;div class="card-body"&amp;gt;

                        @if (session('message'))
                            &amp;lt;div class="alert alert-success" role="alert"&amp;gt;
                                {{ session('message') }}
                            &amp;lt;/div&amp;gt;
                        @endif

                        &amp;lt;table class="table"&amp;gt;
                            &amp;lt;tr&amp;gt;
                                &amp;lt;th&amp;gt;User name&amp;lt;/th&amp;gt;
                                &amp;lt;th&amp;gt;Email&amp;lt;/th&amp;gt;
                                &amp;lt;th&amp;gt;Registered at&amp;lt;/th&amp;gt;
                                &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;
                            &amp;lt;/tr&amp;gt;
                            @forelse ($users as $user)
                                &amp;lt;tr&amp;gt;
                                    &amp;lt;td&amp;gt;{{ $user-&amp;gt;name }}&amp;lt;/td&amp;gt;
                                    &amp;lt;td&amp;gt;{{ $user-&amp;gt;email }}&amp;lt;/td&amp;gt;
                                    &amp;lt;td&amp;gt;{{ $user-&amp;gt;created_at }}&amp;lt;/td&amp;gt;
                                    &amp;lt;td&amp;gt;&amp;lt;a href="{{ route('admin.users.approve', $user-&amp;gt;id) }}"
                                           class="btn btn-primary btn-sm"&amp;gt;Approve&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;
                                &amp;lt;/tr&amp;gt;
                            @empty
                                &amp;lt;tr&amp;gt;
                                    &amp;lt;td colspan="4"&amp;gt;No users found.&amp;lt;/td&amp;gt;
                                &amp;lt;/tr&amp;gt;
                            @endforelse
                        &amp;lt;/table&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
@endsection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final visual result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvfqosp9al774zq4kh9q2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvfqosp9al774zq4kh9q2.png" alt="Laravel administrator approve users" width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So here's probably the quickest way to approve new registered users in Laravel. Pretty simple, huh?&lt;/p&gt;

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