DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Laravel breeze vs Jetstream
oyedeletemitope
oyedeletemitope

Posted on

Laravel breeze vs Jetstream

Introduction

laravel offers several options for authentication in your applications to provide a robust and modern scaffolding for our authentication layer. Laravel starter kits are one of those options and this consists of breeze and jetstream.

Laravel Breeze is an excellent choice when it comes to getting things running quickly, And then there’s jetstream which offers two-factor auth, API tokens, and team management. If you are looking for additional features then jetstream is for you.

In this article, We will be exploring everything you need to know about getting started with both starter kits packages. We will look at the installation guide, discuss the differences between them, their similarities, and when to use them. So let's get started
Objectives

At the end of this article, we should be able to:

  • Know what Laravel and jetstream are.
  • Install Laravel and jetstream.
  • Know their similarities.
  • Identify their differences.
  • Know when to use them.

Prerequisites

To continue with this article you must have had prior knowledge as to what laravel is, and have Laravel 8 installed on your pc. If not you can check out their documentation to get started with Laravel and also its installation process. You must also have a PHP version of 7.3 and above.

Laravel Breeze

Laravel Breeze is an implementation of all of Laravel’s authentication features, The Breeze in essence is a scaffold for solid authentication flow in your Laravel application with sleek views, component system, and a basic dashboard layout; it is built with Laravel Blade.

If you’ve used Laravel before, Laravel Breeze is an upgrade of Laravel UI which sets up basic login, register logout, forgot password, create a password, email verification, and password confirmation functionality so you can customize it to your needs, Breeze doesn't rely on any job script framework, just Laravel, and blade. It does use the tailwind framework which is a CSS framework for the styling. If you haven’t heard of tailwind before it is a styling meaning of CSS. To learn more about tailwind visit this link.

Laravel Breeze creates all the controllers, routes, and views needed to set up and configure authentication features and functionality.

Installation

The installation looks pretty straightforward. For us to install Laravel Breeze, let’s head over to our terminal and run the following composer command:

composer require laravel/breeze --dev 
Enter fullscreen mode Exit fullscreen mode

Next, we run our artisan command below to complete this installation:

php artisan breeze:install
Enter fullscreen mode Exit fullscreen mode

This installs the necessary views, styles, and scaffolding. You will get the following output saying: breeze scaffolding successfully.

Run your npm install && npm run dev command to get our dependencies installed and compile our frontend assets.

npm install && npm run dev
Enter fullscreen mode Exit fullscreen mode

Visit your domain name or server IP address via your browser, you will be able to see the default Laravel page with a login and register link at the top.
laravel breeze

Let’s take a look at the file structure which includes the routes, the view, and the controllers and can be found at standard locations.

Routes

The route is a way of creating a request URL for your application. The route files are located in the routes/auth.php file, which, on the other hand, is included directly in your web.php file with the following line:

require__DIR__.'/auth.php';
Enter fullscreen mode Exit fullscreen mode

Opening the auth.php is a list of authentication routes which includes routes for logging in, registration, password reset, email validation, password confirmation, and logging out.

Controllers

Controllers accept commands from the model and convert them so the data can be used by the view. All routers are directly linked to the controller. The Auth controllers are stored in app/Http/Controllers/Auth/.
In the folder, we have the following controllers:

  • AuthenicatedSessionController.php
  • ConfirmablePasswordController.php
  • EmailVerificationNotificationController.php
  • NewPasswordController.php
  • PasswordResetLinkController.php
  • RegisterdUserController.php
  • VerifyEmailController.php

Views

Views are methods in Laravel that separate the controller logic and domain logic from the presentation logic. Views are located in resources/views/auth/.

The list of blade views available include:

  • confirm-password.blade.php
  • forgot -password.blade.php
  • login.blade.php
  • register.blade.php
  • reset-password.blade.php

When should you use Breeze?

Breeze is perfect for you when:

  • Your app mainly consists of an ordinary Laravel blade template or if you want to rapidly get authentication added to an application without a large amount of opinion needed code.
  • You want to modify the authentication functionality of your app quickly.
  • You're building an app from scratch that doesn't require the features that fortify or Jetstream provide.
  • You just want a more up-to-date Laravel UI.

Now let’s move on to Jetstream.

Jetstream

Jetstream takes things a bit more advanced than Breeze, It adds a lot more features than the basic authentication features that we need. It’s a package that’s much bigger than Breeze. In Jetstream we get:

  • Login and registration functionality
  • Email verification
  • Two-factor authentication
  • Session management
  • API authentication with Sanctum
  • Team management

Jetstream is meant to be a framework within a framework giving you a scaffold and library features to build a fully functioning Sass dashboard or another type of application out of. Laravel Jetstream is free and open-source.

Jetstream actually uses a package called Fortify. Fortify actually does the job of defining the routes and controllers for implementing the application's authentication features while the Jetstream UI makes requests to those routes.

When Jetstream is installed, the config/fortify.php configuration file is installed into your application. You can use this package if you want to have complete control of your frontend or maybe you're building an API and you don’t even need a front end altogether. Laravel Jetstream is free and open-source

Installation

Jetstream can be installed in different ways, You can use a composer or the Laravel installer

Installing with Laravel installer

Get the latest version of Laravel installer, add --jet flag in order to install a new Laravel Jetstream project:

laravel new project-name --jet
Enter fullscreen mode Exit fullscreen mode

Next thing is to run your migrations:

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

Installing Jetstream with Composer

For installation using composer, you need to run the following command inside your Laravel directory just like you would with any other package:

composer require laravel/jetstream
Enter fullscreen mode Exit fullscreen mode

Once that is finished run the PHP artisan command along with our scaffold of choice

β€’ For those who prefer to use Livewire with Blade run:

php artisan jetstream:install livewire
Enter fullscreen mode Exit fullscreen mode

For those who prefer to use Inertia with Vue run:

php artisan jetstream:install inertia
Enter fullscreen mode Exit fullscreen mode

You may also add the --teams flag to enable Laravel Jetstream team support.

Download and compile assets with npm install and npm run dev

npm install && npm run dev
Enter fullscreen mode Exit fullscreen mode

The command above will build your assets. Finally, make sure to run your migrations:

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

Jetstream has been given its own dedicated subdomain website and if we head over to it here link you can find all the information about what it does.

Authentication

Our newly installed Jetstream comes with a login form,two-factor authentication, registration form password reset, email verification which can all be found in resources/views/auth.

Like I mentioned before, Jetstream uses a package called fortify. You can find the fortify actions in app/actions/Fortify/.

The Fortify configurations can be found in config/fortify.php.

Here you can make changes like enable and disable different features.

Profile Management

Jetstream provides users with user profile management functionality which allows users to update their name, email address, and also upload their profile photos.

The user profile view is stored in resources/views/profile/update-profile-information-form.blade.php.

Just in case you’re using inertia you can find the views in resources/js/Pages/Profile/UpdateProfileInformationForm.vue.

Security

Worried about your application security? That’s not a problem, Laravel Jetstream comes with the standard functionality that allows users to update their password and log out which means it’s more than just safe.

What’s more impressive is that it offers two-factor authentication with QR code, which the users could enable and disable directly. Also, users can log out of other browser sessions as well. The profile Blade views can be found in resources/views/profile/.

And if you are working with inertia, you can find them in resources/js/Pages/Profile/.

Jetstream API

Laravel Jetstream uses Laravel Sanctum to provide a simple token-based API. It is a Laravel package created for the authentication of Single Page Applications (SPAs), mobile applications, and basic token-based APIs.
To know more about APIs with sanctum I’ll recommend reading this article. Using Sanctum, each user can generate API tokens with specific permissions like Create, Read, Update, and Delete (CRUD).

Jetstream Teams

In case you used the --team` flag during your Jetstream installation, your website would be able to support team creation and management.

With the Jetstream teams feature, each user can create and belong to multiple teams.

For more information about Jetstream teams, you can check out their official documentation here.

When should you use Jetstream?

You should use Jetstream if:

  • You're conversant with Laravel Livewire, Inertia, and tailwind or you don’t mind taking time to learn them.
  • You have an understanding
  • You want to immediately start building the core functionality of your app without investing much time in procedures.

Differences

One of the main differences between the two is that Jetstream relies heavily on a frontend stack. It comes with two different options which are the livewire blades and inertia Vue. If you're used to using Vue for your applications, then go down the inertia root otherwise go for live wire and blade. Also if you’ve used Laravel Jetstream before, you will notice that it is a little overwhelming and has a stiff learning curve while Laravel Breeze was developed to get you set up immediately.

Similarities

Their similarities are quite glaring as they are both packages that add pieces of frontend and backend functionality to your application.

Conclusion

So far we’ve explored Laravel Breeze and Jetstream, how to install them, differences, similarities, and also when you can use them. Both have outstanding features for the authentication process these packages were introduced to protect a secured area or restricted actions. You just have to choose the one that best suits your style. Please share if this was helpful.

Top comments (0)

git push

Stop by this week's meme thread!