Overview
If you have a large amount of users, or you need to scale horizontally, it may make sense to store them in a database.
From a fresh Statamic project
If you installed Statamic using the statamic new
command, or created a project based on the statamic/statamic
repo, it will be configured to store users in files.
Statamic comes with an Eloquent driver to make the transition as seamless as possible.
- Ensure you have a database configured.
- In
config/statamic/users.php
, changerepository
toeloquent
. - In
config/statamic/stache.php
, comment out theusers
store. - In
config/auth.php
, comment out thestatamic
provider, and uncomment theeloquent
provider. - Run the
php please auth:migration
command to generates the migration for the role and user group pivot tables. - If you’ve customized your
user
blueprint, edit the migration so it includes those fields as columns, or create a new migration to add them. - Run
php artisan migrate
- Run a command to migrate your file based users into the database.
In an existing Laravel app
If you’ve installed Statamic into an existing Laravel app, it will already be configured to use the Eloquent driver. You will need to run migrations to prepare your database for Statamic’s user and permission setup.
php please auth:migration
php artisan migrate
This will add some columns to the users
table (like super
, and last_login
), and create the role_user
and group_user
pivot tables.
When using
sqlite
ormysql
as your database driver, make sure tocomposer require doctrine/dbal
. We do change theusers
table in our auth migrations and therefore require thedoctrine/dbal
to run the migrations without errors.
This assumes you are happy to use our opinionated setup. If you need something more custom you can create your own user driver.