Laravel provides variety of login method for different projects whether it is web application or API application. Laravel Jetstream is one of the basic authentication package. Jetstream provides all funcionality including login, registration, email verification 2fa, and API authentication using Laravel Sanctum. Laravel Jetstream use Tailwind CSS for designing.
In this article we will use Laravel Jetstream for authentication method. We will create new Laravel 8 project and install Laravel Jetstream. Also Laravel Jetstream is not compitible with existing project. So lets start step by step.
So let's get started:
Open CMD or Terminal and create new Laravel application using composer command.
composer create-project laravel/laravel jetstream
Now change the working directory to project root
cd jetstream
In the second step, we will install Laravel Jetstream package with below composer command.
composer require laravel/jetstream
After the package installation complete, you need to run jetstream:install artisan command. You can install Jetstream with Livewire or inertia. We will install it using Livewire.
php artisan jetstream:install livewire
In this step, we will install NPM packages using below commands one by one.
npm install
npm run dev
After the all packages installed, we need to setup database and migration.
First you need to configure database in .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=jetstream
DB_USERNAME=root
DB_PASSWORD=root
And run the below migrate command to generate tables in database.
php artisan migrate
Run the command to publish Livewire Stack componant
php artisan vendor:publish --tag=jetstream-views
In the .env
file, you may want to setup email configuration as we will use email verification on user register. So setup the email credentials as below.
MAIL_MAILER=smtp
MAIL_HOST=smtp.sendmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=ssl
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
We will put email verification, so remove comment from the config/fortify.php file.
'features' => [
...
Features::emailVerification(),
],
In the last step, you need to change in User model.
<?php
namespace App;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable, HasFactory;
...
}
That's it Now run the project with artisan command.
php artisan serve
Now in the web browser, open http://localhost:8000 and go to login url.
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 remove HTML special characters from a string in PHP
Use the PHP htmlspecialchars() ...Scrolla jQuery plugin for reveal animations when scrolling
If your website contains lots of images,...Laravel 8 CRUD Operation Tutorial using Livewire
We will perpetuate anterior Laravel 8 -...Laravel 8 Image Resize and Upload with Intervention Image
Uploading high size images in blog appli...How to convert URL to array in PHP
An URL is the string of many data. URL c...