How to Use Laravel Jetstream: Setup and Basic Usage Guide
To use
Laravel Jetstream, first install it via Composer in a new Laravel project, then run its installation command to scaffold authentication and UI features. Jetstream provides ready-made login, registration, and profile management with options for Livewire or Inertia stacks.Syntax
Laravel Jetstream is installed and configured using Composer and Artisan commands. The main steps include:
composer require laravel/jetstream: Adds Jetstream package to your Laravel project.php artisan jetstream:install [stack]: Installs Jetstream with your chosen stack, eitherlivewireorinertia.npm install && npm run dev: Compiles frontend assets.php artisan migrate: Runs database migrations for Jetstream features.
Each part sets up authentication UI and backend logic quickly.
bash
composer require laravel/jetstream php artisan jetstream:install livewire npm install && npm run dev php artisan migrate
Example
This example shows how to create a new Laravel project and install Jetstream with Livewire stack for authentication features.
bash
laravel new jetstream-demo
cd jetstream-demo
composer require laravel/jetstream
php artisan jetstream:install livewire
npm install && npm run dev
php artisan migrate
php artisan serveOutput
Starting Laravel development server: http://127.0.0.1:8000
Visit this URL in your browser to see the Jetstream authentication UI with login, registration, and dashboard.
Common Pitfalls
Common mistakes when using Laravel Jetstream include:
- Not running
npm install && npm run devafter installation, causing missing frontend styles and scripts. - Skipping
php artisan migrate, so database tables for users and sessions are missing. - Choosing the wrong stack for your project needs (Livewire vs Inertia).
- Not configuring your database connection before migration.
Always ensure your environment is set up correctly before installing Jetstream.
bash
Wrong way: php artisan jetstream:install livewire php artisan migrate Right way: php artisan jetstream:install livewire npm install && npm run dev php artisan migrate
Quick Reference
Summary tips for using Laravel Jetstream:
- Choose
livewirefor Blade-based reactive UI orinertiafor Vue.js SPA style. - Run
npm install && npm run devafter installation to compile assets. - Configure your database in
.envbefore running migrations. - Use
php artisan migrateto create necessary tables. - Access authentication pages at
/loginand/registerafter setup.
Key Takeaways
Install Laravel Jetstream via Composer and choose your UI stack with the install command.
Always run npm commands to build frontend assets after Jetstream installation.
Run database migrations to create authentication tables before using Jetstream features.
Pick Livewire for Blade or Inertia for Vue.js depending on your project needs.
Configure your database connection properly to avoid migration errors.