email verification during register
1.make account and config .env file
https://mailtrap.io/inboxes/1601388/messages
2.Configratins
app/models/user.php must contain faceds
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
also implements user.php
class User extends Authenticatable implements MustVerifyEmail
{
//
}
Database
user table must contains email_verified_at field, check it from database/migrations/2014_10_12_000000_create_users_table.php if no found add this field and run command
php artisan migrate
Routing
goto routing/web.php and change this
Auth::routes();
to
Auth::routes(['verify' => true]);
Now register a new user and check mailtrap inbox, you will get verification email.
How to ristrict user to access homepage before verification
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
to
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home')->middleware('verified');
Now you first verify then go to home page,
Note:
All pages are inside resources/views/auth you can modify there
To disable verification of email:
1. remove all from routes ->middleware('verified');
2. Change verify true to null
Auth::routes(['verify' => true]);
to
Auth::routes();
3. open app/models/user.php and remove implements MustVerifyEmail