New Jetstream application in laravel with authentication

In this tutorial we are going to create Laravel application with Jetstream Authentication. So first of all Let's understand what is Laravel Jetstream.

Jetstream should only be installed into new Laravel applications. Attempting to install Jetstream into an existing Laravel application will result in unexpected behavior and issues.

What is Laravel Jetstream?

A Laravel Jetstream is a beautifully designed application starter kit for Laravel and provides the perfect starting point for your next Laravel application. Jetstream provides the implementation for your application's login, registration, email verification, two-factor authentication, session management, API via Laravel Sanctum, and optional team management features.

Laravel Jetstream offers us two available frontend stacks.

  1. Livewire
  2. Inertia

Both of them provide us productive and powerful functionality and designing. However you can choose any stack you wish. Let us give you brief about both before creating our application.

Livewire

Livewire is library which use blade template to provide user interface and functionality tp our application. When using Livewire, you may pick and choose which portions of your application will be a Livewire component, while the remainder of your application can be rendered as the traditional Blade templates you are used to.

Inertia

The Inertia stack provided by Jetstream uses Vue.js as its template language. With Inertia.js, you get to build fully client-side rendered apps (Vue.js, React, Svelte), but build those apps in a more classic server-side "monolith" way. With Inertia you don't need an API. Just create controllers and views, with plain old server-side routing, and Inertia turns it into a single-page application.

Create New Laravel Application

Let's begin to create our Laravel application with Jetstream authentication. First of all create new project.

You can create fresh Laravel application with one of the below commands:

    
        composer create-project --prefer-dist laravel/laravel Application_name
        //If you already installed laravel globel installer 
        laravel new Application_name
    

Replace Application_name with your actual project name.

Database Configuration

Let's configure database for our application. If you have don't have any database then create a new one. After creating database open .env file from root directory of your project. if .env file is missing from project then copy content from .env.example and create file. .env file defines many common environment variables

    
        DB_CONNECTION=mysql  
        DB_HOST=127.0.0.1  
        DB_PORT=3306  
        DB_DATABASE=********** 
        DB_USERNAME=*********
        DB_PASSWORD=*********
    

Replace * with your actual configuration in upper code.

Installing Jetstream to Laravel Application

we are going to use composer to install Jetstream into our project so open terminal or command prompt and navigate to your project root directory. Enter following command to install Jetstream:

    
        composer require laravel/jetstream
    

Installing Jetstream Livewire/Inertia

After installing the Jetstream package, we have to execute the jetstream:install Artisan command. We have to pass stack name which we want to use in application (livewire or inertia). In addition, we can also pass --teams switch to enable team support.

Enter Following command to terminal:

    
        //For Livewire stack
        php artisan jetstream:install livewire
        //If you want to install livewire with teams
        php artisan jetstream:install livewire --teams

        //For Inertia
        php artisan jetstream:install inertia
        //For Inertia with teams
        php artisan jetstream:install inertia --teams
    

Finalizing The Installation

After installing Jetstream, we have to install and build our NPM dependencies. For that enter below commands to terminal or command prompt:

    
        npm install
        npm run dev
    

It will take some time to install NPM dependencies. After installation you will receive message like Laravel mix, build successful.

Migrate Database

Let's run all outstanding migrations, execute the migrate Artisan command:

    
        php artisan migrate
    

Our Laravel application with Jetstream Authentication is created successfully. For testing application we need to run local serve using artisan command:

    
        php artisan serve 
        //If you want to run application on specific port then use this command.
        php artisan serve –port=8080
    

Open below URL into browser to see output:

    
        http://127.0.0.1:8000
    

Conclusion

Here, we have created new Laravel application using Jetstream authentication. It's upon you to choose Livewire or Inertia. But be aware of that installing Jetstream after developing some functionality can cause you errors.


Share your thoughts

Ask anything about this examples