Laravel Jetstream - a new scaffolding for the framework

The Laravel 8 release brought with it a new framework to quickly deploy a user authentication system that includes login, registration, email confirmation, two-factor authentication, session and command management. Jetstream also has built-in Laravel Sanctum integration for token-based API authentication.



image



Choosing a stack



Laravel Jetstream comes with two front-end stacks - Livewire and Inertia.js . Both stacks add reactivity to your application, the difference between them is that Livewire uses Blade as its templating engine, and Inertia.js uses Vue. Tailwind is used as the CSS framework in both cases.



Installation



If we create a new project, then we can use the Laravel Installer with a flag --jet. The installation will be interactive and will prompt you to select the stack and manage teams. After installation, you need to migrate to the database:

laravel new project-name --jet
php artisan migrate


Add the package to the finished project using Composer:

composer require laravel/jetstream


Then, depending on the selected stack, choose one of the two. If command management is not required, then the flag --teamsshould be removed.



Livewire:

php artisan jetstream:install livewire --teams


Inertia.js:

php artisan jetstream:install inertia --teams


We finish the installation by installing NPM packages and migrating the database:

npm install && npm run dev
php artisan migrate


User profile



Laravel Jetstream allows the user to go to their profile, update their information, and even upload a photo. You can disable the ability to install photos inconfig/jetstream.php

image



Two-factor authentication



After enabling two-factor authentication, the user must save the recovery codes and also scan the resulting QR code using the One-Time Password-enabled application - a dynamic password. This could be, for example, Google Authenticator or 1Password.

image



API



Jetstream is integrated with Sanctum and allows the user to generate access tokens with different rights: create, read, update and delete. You can disable this feature inconfig/jetstream.php

image



Commands



If you installed Jetstream with the option teams, you will get a command management interface. Each user can be a member of one or several teams. By default, a new user is a member of the team named after him. For example, for user John, this would be John's Team.



The user can rename this command or create additional ones. You can invite other users to your team only knowing their email address and they must already be registered on the site. The team owner assigns roles to other members. Roles can be Administrator or Editor. Administrator has full rights when Editor can only read, create and update. That is, it has all the same rights, except for deletion.

image



All Articles