Authentication scaffolding accelerates project starts. Laravel Jetstream replaces Laravel UI with modern features: two-factor auth, team management, and API tokens. At ZIRA Software, Jetstream powers SaaS application foundations.
Installation
composer require laravel/jetstream
# With Livewire
php artisan jetstream:install livewire
# With Inertia.js + Vue
php artisan jetstream:install inertia
# With teams feature
php artisan jetstream:install livewire --teams
# Migrate and build
npm install && npm run dev
php artisan migrate
Features Included
Out of the box:
- Login / Registration
- Email verification
- Two-factor authentication
- Session management
- API token management (Sanctum)
- Team management (optional)
- Profile management
Two-Factor Authentication
Automatic implementation:
// Enabled by default in Jetstream
// Users can enable 2FA from profile page
Usage:
- User enables 2FA in profile
- Generates QR code for authenticator app
- Provides recovery codes
- Login requires 2FA code
Team Management
When installed with --teams:
// models/Team.php
class Team extends JetstreamTeam
{
protected $fillable = ['name', 'personal_team'];
public function users()
{
return $this->belongsToMany(User::class, Membership::class)
->withPivot('role')
->withTimestamps()
->as('membership');
}
}
// Usage
$team = auth()->user()->currentTeam;
$team->users; // All team members
// Check team membership
if (auth()->user()->ownsTeam($team)) {
// Owner actions
}
Team roles:
// app/Providers/JetstreamServiceProvider.php
Jetstream::defaultApiTokenPermissions(['read']);
Jetstream::permissions([
'create',
'read',
'update',
'delete',
]);
Jetstream::role('admin', 'Administrator', [
'create', 'read', 'update', 'delete',
])->description('Administrator users have full access.');
Jetstream::role('editor', 'Editor', [
'read', 'create', 'update',
])->description('Editors can create and update content.');
API Tokens
Create tokens:
<!-- Built-in UI for token management -->
<x-jet-form-section>
<x-slot name="title">Create API Token</x-slot>
<!-- Token creation form -->
</x-jet-form-section>
Usage:
$token = $user->createToken('Mobile App', ['posts:read', 'posts:create']);
// Use token
$response = Http::withToken($token->plainTextToken)
->get('https://api.example.com/posts');
Profile Management
Update profile:
// Automatic form in Jetstream
// Updates: name, email, photo
Customization:
// app/Actions/Fortify/UpdateUserProfileInformation.php
public function update($user, array $input)
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
])->validateWithBag('updateProfileInformation');
if (isset($input['photo'])) {
$user->updateProfilePhoto($input['photo']);
}
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
])->save();
}
Customizing Actions
Custom actions:
php artisan vendor:publish --tag=jetstream-actions
Example customization:
// app/Actions/Jetstream/CreateTeam.php
public function create($user, array $input)
{
Gate::forUser($user)->authorize('create', Jetstream::newTeamModel());
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
])->validateWithBag('createTeam');
$team = $user->ownedTeams()->create([
'name' => $input['name'],
'personal_team' => false,
]);
$user->switchTeam($team);
return $team;
}
Conclusion
Laravel Jetstream provides production-ready authentication with modern features. Two-factor auth and team management eliminate common development tasks.
Starting a new Laravel project? Contact ZIRA Software for rapid development with Jetstream.