Install and connect the application | laravel-permission-rust | Spatie       

 SPATIE  

laravel-permission-rust
=======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-permission-rust](https://spatie.be/docs/laravel-permission-rust/v1)  Install and connect the application

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-permission-rust/v1) 

  Install and connect the application    
- [ Introduction ](https://spatie.be/docs/laravel-permission-rust/v1/introduction)
- [ Install and connect the application ](https://spatie.be/docs/laravel-permission-rust/v1/installation-laravel)
- [ Roles and permissions ](https://spatie.be/docs/laravel-permission-rust/v1/basic-usage)
- [ Authenticated routes and policies ](https://spatie.be/docs/laravel-permission-rust/v1/authorization)
- [ Querying users and bulk assignment ](https://spatie.be/docs/laravel-permission-rust/v1/querying-users)
- [ Console commands ](https://spatie.be/docs/laravel-permission-rust/v1/commands)
- [ Custom models and IDs ](https://spatie.be/docs/laravel-permission-rust/v1/models-and-ids)
- [ Cache and events ](https://spatie.be/docs/laravel-permission-rust/v1/cache-and-events)
- [ Integration tests ](https://spatie.be/docs/laravel-permission-rust/v1/testing)

 Install and connect the application
===================================

###  On this page 

1. [ Configuration ](#content-configuration)

Install and connect the application
=================================================================================================================================================================

Use the Git dependency and migration in the [README](https://github.com/spatie/laravel-permission-rust/blob/main/README.md). Rust 1.99+ is required by the framework. The crate is not published to crates.io.

Your account model must implement Laravel's `Model` and `Authenticatable`. Use the framework derive and real provider. This is the same setup the integration tests use:

```
use laravel::{Application, auth::{Authenticatable, RememberToken}, hash::PasswordHash, model::{self, model}};
use spatie_permission::{PermissionConfig, Role, service_provider};

#[model(table = "accounts")]
#[derive(Authenticatable)]
pub struct Account {
    pub id: i64,
    pub email: String,
    #[serde(skip)]
    pub password: PasswordHash,
    #[serde(skip)]
    pub remember_token: Option<RememberToken>,
}

let app = Application::configure()
    .with_providers(|providers| { providers.add(service_provider::<Account, Role>()); })
    .with_config(|config, _| {
        let mut permissions = config.section::<PermissionConfig>().clone();
        permissions.teams = true;
        config.set(permissions);
    })
    .with_auth(|auth, _| { auth.session::<model::Users<Account>>(); })
    .create();
```

Create your `accounts` table in its own registered migration, with an ID, unique email, password and remember token. Configure the SQLite connection with `DB_CONNECTION=sqlite` and `DATABASE_URL=sqlite://app.sqlite?mode=rwc`. Real web routes need `APP_KEY` for encrypted cookies. The framework's `.for_testing(...)` generates a test key; it is not a production key.

The package does not own the application or open a parallel database connection. Every query uses Laravel's current application context and its ambient transaction. Outside HTTP, use `app.scope(async || { ... })`. Register the permission migration once; it is not run by the registrar's constructor.

The default models use integer role and permission keys. For application-owned models, UUIDs, ULIDs, custom columns or timestamps, see [custom models and IDs](models-and-ids). Use the same model selection for the registrar, migration, commands and middleware.

Configuration
-----------------------------------------------------------------------------------------------

The provider reads `PermissionConfig` through Laravel's `Env` parser. Invalid booleans or durations fail application startup. Application `.with_config` callbacks run after provider defaults; application `.with_services` bindings may replace `Registrar<Role>` entirely.

- `PERMISSION_GUARD`: default namespace, `web`.
- `PERMISSION_TEAMS`: enable team contexts, `false`.
- `PERMISSION_WILDCARD`: enable wildcard checks, `false`.
- `PERMISSION_EVENTS`: dispatch assignment events, `false`.
- `PERMISSION_DISPLAY_PERMISSION` and `PERMISSION_DISPLAY_ROLE`: include required names in middleware denials, both `false` to avoid disclosing application abilities.
- `PERMISSION_CACHE_KEY`: permission-name catalog key, `spatie.permission.names`.
- `PERMISSION_CACHE_SECONDS`: catalog TTL in seconds, `86400`.
- `PERMISSION_CACHE_STORE`: named Laravel cache store, unset or `default` uses the application default.

Select models with provider generics and native model traits, not runtime class-name strings. Set `PermissionConfig::wildcard` to an `Arc<dyn Wildcard>` for custom interpretation. The provider does not create a user model, register authentication, run migrations or install middleware implicitly. Use one selected registrar type consistently throughout the application.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
