Laravel 5.3 : Sending an email verification after registering new user in Laravel 5.3

laravel 5.3 tutorials : how to send an email Confirmation Mail for User Registration Using laravel 5.3 php framework?

Laravel 5.3 tutorial for beginners - This is New lessons about Laravel 5.3 tutorial that is how er can sending the activation or confirmation email to the new users email address after they're register in our laravel applications.

UPDATED : 
New versions is available here "Email Verification for New User After Registration in Laravel 5.3"

At the previews lessons, we have learn about How to Send Email using Gmail SMTP in laravel 5.3 and VB.NET Simple Application Send Mail SMTPClient gmail.com + Source Code.

Email verification in laravel 5.3

To create simple email verification we will using "jrean" packages, https://packagist.org/packages/jrean/laravel-user-verification.

Create Email Verivication Project

first, following artisan command to create new project in laravel using Composer.

cd c:\server\htdocs
....
composer create-project --prefer-dist laravel/laravel verification

Create Database & Connection

to create database and connection in laravel 5.3, just click link on here How to Connect Database in laravel 5.3.

JREAN PACKAGES INSTALLATION

This project can be installed via Composer. To get the latest version of Laravel User Verification, add the following line to the require block of your composer.json file:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",
        "jrean/laravel-user-verification": "^3.0"
    },

Next, You'll then need to run composer install or composer update to download the package and have the autoloader updated.

Other method to install "jrean" packages, following this command

composer require jrean/laravel-user-verification

Add the Service Provider & Facade/Alias

Once Larvel User Verification is installed, you need to register the service provider in config/app.php. Make sure to add the following line above the RouteServiceProvider.

....
Jrean\UserVerification\UserVerificationServiceProvider::class,
....

Create Laravel 5 User Authentication

before we add more "jrean" function, we nedd to create authentication to our project, create it following by this command :

php artisan make:auth

Create New Migration

The table representing the user must be updated with two new columns, verified and verification_token. This update will be performed by the migrations included with this package.

It is mandatory that the two columns are on the same table where the user's e-mail is stored. Please make sure you do not already have those fields on your user table.


To run the migrations from this package use the following command :

php artisan migrate --path="/vendor/jrean/laravel-user-verification/src/resources/migrations"

Register the default middleware

To register the default middleware add the following to the $routeMiddleware array within the app/Http/Kernel.php file:

// ........
'isVerified' => Jrean\UserVerification\Middleware\IsVerified::class,

Apply to our routes (routes/web.php)

Route::group(['middleware' => ['web', 'isVerified']], function () {
    //....

Create New Views

If you want to customize the e-mail view, run the following command to publish it and edit it to your needs:

php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationServiceProvider" --tag="views"

The view will be available in the resources/views/vendor/laravel-user-verification/ directory.

Create New Routes

By default this packages ships with two routes. If you want to change them, you can simply define your own routes.

Route::get('email-verification/error', 'Auth\RegisterController@getVerificationError')->name('email-verification.error');
Route::get('email-verification/check/{token}', 'Auth\RegisterController@getVerification')->name('email-verification.check');

Update Controller (app\Http\Controllers\Auth\RegisterController.php)

  1. Import the VerifiesUsers trait (mandatory)
  2. Overwrite and customize the redirect attributes/properties paths available within the RedirectsUsers trait included by the VerifiesUsers trait. (not mandatory)
  3. Overwrite the contructor (not mandatory)
  4. Overwrite the register() method (mandatory)
<?php 
    namespace AppHttpControllersAuth;

    use App\User;
    use Validator;
    use App\Http\Controllers\Controller;
    use Illuminate\Foundation\Auth\Registers\Users;
    use Illuminate\Http\Request;

    use Jrean\UserVerification\Traits\VerifiesUsers;
    use Jrean\UserVerification\Facades\UserVerification;


    class RegisterController extends Controller
    {
        /*
        |--------------------------------------------------------------------------
        | 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.
        |
        */

        use RegistersUsers;

        use VerifiesUsers;

       /**
        * Create a new controller instance.
        *
        * @return void
        */
        public function __construct()
        {
            // Based on the workflow you need, you may update and customize the following lines.

            $this->middleware('guest', ['except' => ['getVerification', 'getVerificationError']]);
        }

        /**
        * Get a validator for an incoming registration request.
        *
        * @param  array  $data
        * @return IlluminateContractsValidationValidator
        */
        protected function validator(array $data)
        {
            return Validator::make($data, [
                'name' => 'required|max:255',
                'email' => 'required|email|max:255|unique:users',
                'password' => 'required|min:6|confirmed',
            ]);
        }

        /**
        * Create a new user instance after a valid registration.
        *
        * @param  array  $data
        * @return User
        */
        protected function create(array $data)
        {
            return User::create([
                'name' => $data['name'],
                'email' => $data['email'],
                'password' => bcrypt($data['password']),
            ]);
        }

        /**
        * Handle a registration request for the application.
        *
        * @param  IlluminateHttpRequest  $request
        * @return IlluminateHttpResponse
        */
        public function register(Request $request)
        {
            $this->validator($request->all())->validate();

            $user = $this->create($request->all());
            $this->guard()->login($user);

            UserVerification::generate($user);
            UserVerification::send($user, 'My Custom E-mail Subject');

            return redirect($this->redirectPath());
        }
    }

Video Tutorial Sending an email verification after registering new user in Laravel 5.3


List video's Laravel 5.3 tutorials (Make a blog)



Learning Laravel 5.3



Download full source code from here https://goo.gl/flna2j
see you next lessons...

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: Laravel 5.3 : Sending an email verification after registering new user in Laravel 5.3
Laravel 5.3 : Sending an email verification after registering new user in Laravel 5.3
laravel 5.3 tutorials : how to send an email Confirmation Mail for User Registration Using laravel 5.3 php framework?
https://i.ytimg.com/vi/2aCCE-dhWic/hqdefault.jpg
https://i.ytimg.com/vi/2aCCE-dhWic/default.jpg
KODE AJAIB
https://www.kodeajaib.com/2016/10/sending-email-verification-after-registering-new-users.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2016/10/sending-email-verification-after-registering-new-users.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy