Laravel Jetstream is a beautifully designed application scaffolding for Laravel. Jetstream includes login, registration, email verification, two-factor authentication, session management, API support via Laravel Sanctum, and optional team management. Laravel Jetstream replaces and improves upon the legacy authentication UI scaffolding available for previous versions of Laravel.
In this tutorial we will show you the steps to setup the basic Jetstream setup with email verification after registering.
First we need to create laravel 8 application in our local system help of run the following command in terminal.
composer create-project --prefer-dist laravel/laravel blog
composer require laravel/jetstream
After installing Jetstream, you should install and build your NPM dependencies
npm install
php artisan migrate
After installing jetstream you will have autogenerated files in resources/views directory.
uncomment the relevant entry in the features configuration item of the config/fortify.php configuration file
'features' => [
...
Features::emailVerification(),
...
],
Next you need to setup your email settings through which reistration mail willbe sent. You can setup this in your .env file. Below is gmail account setup example. To send email through gmail account you need to enable the two factor email verification and generate application name nd password.you can check the steps for two factor email verification.
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=ssl
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
Edit app\Models\User.php as below
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens;
use HasFactory;
use HasProfilePhoto;
use Notifiable;
use TwoFactorAuthenticatable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
'two_factor_recovery_codes',
'two_factor_secret',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [
'profile_photo_url',
];
}
Now run the application to see the output.You will see the login, register link.
After register one email will be sent to your registered email account. and by clicking on the verification link you can verify your account and then can login.
After login on top right corner there will be dropdown to manage profile, manage account, team, etc.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Make a Redirect in PHP
Use the PHP header() Function You can...Laravel 7 Highcharts Tutorial Example
In this tutorial, i am going to show you...How to Get the ID of the Element that Fired an Event in jQuery
Use the event.target Property You can...How to use Null coalescing operator in PHP
PHP provides ternary operator for if...e...How to Count Number of Rows in a Table Using jQuery
Use the length Property You can simpl...