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/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. You can also create a new migration file by runningphp artisan make:migration
. You'll have to manually edit the migration file to reflect your changes. Read up on Laravel database migrations here. - Run
php artisan migrate
- Run a command to migrate your file based users into the database.
- (optional) If you are using the Statamic forgot password form, add the following method to your User model
public function sendPasswordResetNotification($token){$this->notify(new \Statamic\Notifications\PasswordReset($token));}
Simon Hamp has a good starter migration script you can start from and customize for your own needs.
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, password reset, and permission setup.
-
Configure the two separate password reset drivers. Unlike a regular Laravel installation, Statamic has a second table to track password activations which are the same as resets, but last a little longer before they expire. This is optional.
In
config/auth.php
add the following inside thepasswords
array:'activations' => ['provider' => 'users','table' => 'password_activation_tokens','expire' => 4320,'throttle' => 60,],In
config/statamic/users.php
change thepasswords
array to:'passwords' => ['resets' => 'users','activations' => 'activations',], -
Create and run the migrations.
This will add some columns to the
users
table (likesuper
, andlast_login
), create therole_user
andgroup_user
pivot tables, and create thepassword_activations
table.php please auth:migrationphp artisan migrate -
(optional) If you are using the Statamic forgot password form, add the following method to your User model
public function sendPasswordResetNotification($token){$this->notify(new \Statamic\Notifications\PasswordReset($token));}
When using sqlite
or mysql
as your database driver, make sure to composer require doctrine/dbal
. We change the users
table in our auth migrations and therefore require the doctrine/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.