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.
config/statamic/stache.php, comment out the
config/auth.php, comment out the
statamicprovider, and uncomment the
- Run the
php please auth:migrationcommand to generates the migration for the role and user group pivot tables.
- If you’ve customized your
userblueprint, edit the migration so it includes those fields as columns, or create a new migration to add them.
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
last_login), and create the
group_user pivot tables.
mysqlas your database driver, make sure to
composer require doctrine/dbal. We do change the
userstable in our auth migrations and therefore require the
doctrine/dbalto 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.