Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How does Laravel Splade handle authentication and authorization
    Laravel Splade authentication authorization Laravel Breeze SPA Blade templates Laravel


How does Laravel Splade handle authentication and authorization


Laravel Splade provides a seamless way to handle authentication and authorization in your Single Page Application (SPA) using standard Laravel Blade templates. Here's how it works:

Authentication

To get started with authentication, you can use the Laravel Breeze starter kit that has been forked with a Laravel Splade implementation[2][3]. This provides a minimal, simple implementation of all of Laravel's authentication features, including login, registration, password reset, email verification, and password confirmation.

The installation process is similar to the Automatic Installation of Laravel Splade[3]:

bash
laravel new example-app
cd example-app
composer require protonemedia/laravel-splade-breeze
php artisan breeze:install

The `breeze:install` command will also build the frontend assets. You can then run the Vite development server:

bash
npm run dev

Authorization

Laravel Splade integrates with Laravel's built-in authorization system. You can use the `@can` directive in your Blade templates to conditionally render content based on the user's permissions[1]:

html
@can('update', $post)
    <!-- The current user can update the post -->
@elsecan('delete', $post)
    <!-- The current user can delete the post -->
@else
    <!-- The current user can't update or delete the post -->
@endcan

You can also use the `@cannot` directive to check if the user does not have a certain permission[1]:

html
@cannot('update', $post)
    <!-- The current user can't update the post -->
@endcannot

By leveraging Laravel's built-in authentication and authorization features, Laravel Splade makes it easy to secure your SPA without the need for additional setup or configuration.

Citations:
[1] https://laraveldaily.com/course/laravel-splade-spa
[2] https://github.com/protonemedia/laravel-splade-breeze
[3] https://splade.dev/docs/breeze
[4] https://packagist.org/packages/protonemedia/laravel-splade-breeze
[5] https://splade.dev