Laravel Jetstream Documentation

repository·5.x·Indexed 26 days ago

https://github.com/laravel/jetstream

A starter kit for Laravel applications providing a foundation for modern web apps with features including authentication, team management, and profile management. Includes documentation on managing two-factor authentication, session drivers for browser logout, role and permission configuration, and extending team actions via service providers.

Tokens
4.1K
Snippets
10
Records
26
Agent score
87%

What's inside Laravel Jetstream

  1. Upgrade Jetstream to 4.x

    5.x

    To upgrade to Jetstream 4.x, update your laravel/jetstream dependency to ^4.0 in composer.json and run composer update.

    Livewire Stack Specifics

    If you are using the Livewire stack, ensure you have already upgraded to Livewire 3.x and run php artisan livewire:upgrade on published views. Since Livewire 3 includes Alpine by default, remove Alpine from resources/js/app.js. You must add @livewireStyles and @livewireScripts to resources/views/layouts/guest.blade.php to support guest components.

    composer update
    # For Livewire stack views
    php artisan livewire:upgrade
  2. Upgrade Jetstream to 3.x

    5.x

    To upgrade to Jetstream 3.x, follow these steps:

    1. Publish Views: Run php artisan vendor:publish --tag=jetstream-views (skip if already published).
    2. Update Dependency: Set laravel/jetstream to ^3.0 in composer.json and run composer update.

    Livewire Stack Migration

    • Move components from resources/views/vendor/jetstream/components to resources/views/components.
    • Move mail views from resources/views/vendor/jetstream/mail to resources/views/emails.
    • Remove the jet- prefix from all component tags (e.g., <x-jet-banner /> becomes <x-banner />).
    • Clear view cache: php artisan view:clear.

    Inertia Stack Migration

    • Move mail views from resources/views/vendor/jetstream/mail to resources/views/emails.
    • Update authenticated user references: change $page.props.user to $page.props.auth.user and usePage().props.user to usePage().props.auth.user.
    • Clear view cache: php artisan view:clear.
    php artisan vendor:publish --tag=jetstream-views
    composer update
    php artisan view:clear
  3. Upgrade Jetstream to 2.x

    5.x

    To upgrade to Jetstream 2.x, follow these steps:

    1. Publish Views: Run php artisan vendor:publish --tag=jetstream-views.
    2. Update Dependency: Set laravel/jetstream to ^2.0 in composer.json and run composer update.
    3. New Actions: Place RemoveTeamMember and InviteTeamMember in app/Actions/Jetstream and register them in JetstreamServiceProvider::boot().
    4. Team Invitation Model: Add the TeamInvitation model to app/Models and create a team_invitations migration.

    Livewire Stack

    • Rename resources/views/navigation-dropdown.blade.php to resources/views/navigation-menu.blade.php and update references in app.blade.php.

    Inertia Stack

    • Authentication: Either publish Vue-based auth pages using php artisan vendor:publish --tag=jetstream-inertia-auth-pages or manually configure Blade views in JetstreamServiceProvider::boot() using Fortify::loginView, Fortify::registerView, etc.
    • Cleanup: Remove import {InertiaForm} from 'laravel-jetstream'; and Vue.use(InertiaForm); from resources/js/app.js, then run npm uninstall laravel-jetstream.
    php artisan vendor:publish --tag=jetstream-views
    composer update
    php artisan make:migration create_team_invitations_table
    npm uninstall laravel-jetstream
  4. Upgrade Jetstream to 5.x

    5.x

    To upgrade to Jetstream 5.x, update your laravel/jetstream dependency to ^5.0 in composer.json and run the update command. Note that upgrading Laravel, Tailwind, Livewire, or Inertia is handled separately by their respective documentation.

    composer update
  5. Configure the Inertia.js application entrypoint

    5.x

    The app.js file serves as the entrypoint for Inertia.js applications using Vue 3. It uses createInertiaApp to initialize the application, resolve page components, and set up global plugins like ZiggyVue.

    Key configuration options include:

    • title: A function to define the document title format. It receives the page title and can append an application name.
    • resolve: A function to resolve page components. In this stub, it uses resolvePageComponent to dynamically import Vue files from the ./Pages/ directory.
    • setup: A function that receives the application instance components (el, App, props, plugin) and is responsible for mounting the Vue application and registering plugins.
    • progress: Configuration for the Inertia progress bar, such as the color.
    import { createApp, h } from 'vue';
    import { createInertiaApp } from '@inertiajs/vue3';
    import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
    import { ZiggyVue } from '../../vendor/tightenco/ziggy';
    
    const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
    
    createInertiaApp({
        title: (title) => `${title} - ${appName}`,
        resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
        setup({ el, App, props, plugin }) {
            return createApp({ render: () => h(App, props) })
                .use(plugin)
                .use(ZiggyVue)
                .mount(el);
        },
        progress: {
            color: '#4B5563',
        },
    });
  6. Publish Jetstream assets and configuration

    5.x

    You can publish various Jetstream assets to your application using specific vendor tags. This allows you to customize configuration, migrations, routes, and Inertia components.

    Use the following tags with the php artisan vendor:publish command:

    • jetstream-config: The jetstream.php configuration file.
    • jetstream-migrations: The base users table migration.
    • jetstream-team-migrations: Migrations required for Team features.
    • jetstream-routes: The Jetstream route file.
    • jetstream-inertia-auth-pages: Inertia/Vue authentication pages and components (only applicable if using the Inertia stack).
  7. Configure session driver for logout other browser sessions

    5.x

    The LogoutOtherBrowserSessionsForm component requires the Laravel session driver to be set to database to function. If the session.driver is not set to database, the component will not be able to retrieve session lists or perform the logout of other devices.

    Ensure your config/session.php is configured with:

    • driver => 'database'
    • table => 'sessions' (or your custom sessions table)
    • connection => your database connection name
  8. Use the API Index page component

    5.x

    The Pages/API/Index.vue component serves as the interface for managing API tokens. It requires specific props to be passed from the Inertia controller to render the token list and permission management functionality via the ApiTokenManager partial.

    Required Props

    PropTypeDescription
    tokensArrayA list of the user's existing API tokens.
    availablePermissionsArrayA list of all permissions available to be assigned to tokens.
    defaultPermissionsArrayThe set of permissions that are assigned by default when a new token is created.
    // Example of how the component is structured via props
    // This is typically rendered by an Inertia response from a Laravel controller
    <Index 
        :tokens="tokens" 
        :available-permissions="availablePermissions" 
        :default-permissions="defaultPermissions" 
    />
  9. Configure Jetstream Models

    5.x

    If you are using custom Eloquent models instead of the defaults, you can specify them using the Jetstream class. This affects how Jetstream interacts with users, teams, memberships, and invitations.

    • useUserModel(string $model): Sets the user model.
    • useTeamModel(string $model): Sets the team model.
    • useMembershipModel(string $model): Sets the membership model.
    • useTeamInvitationModel(string $model): Sets the team invitation model.
  10. Use Jetstream banner macros for redirects

    5.x

    Jetstream provides several macros for the RedirectResponse class to easily display flash messages using different banner styles. These macros automatically set the flash session data with the appropriate bannerStyle and banner message.

    Available macros:

    • banner($message): Sets bannerStyle to success.
    • warningBanner($message): Sets bannerStyle to warning.
    • dangerBanner($message): Sets bannerStyle to danger.