June 15th, 2023
With Solo Licence of Statamic, you can have multiple users, but only if you don't need them to have permission to control panel of Statamic. For example, you can have multiple Laravel Users that see front-end content based on authentication or permissions, but only one super user (Statamic User) that has access to control panel to create, edit content. If multiple users need permission to control panel, then you need Statamic Pro license.
After installing Statamic into Laravel application, we create users.
We'll separate users. Statamic User, admin user with access to control panel will be saved to yaml file, other users, Laravel Users, just for frontend content, in database. Let's edit config files.
config/statamic/users/php
Repository 'file' driver gets it from disk, while the 'eloquent' driver gets from a database
By default, Statamic will use the web
authentication guard. But we can also run Statamic alongside the default Laravel auth guard. We'll create guard statamic
for when using control panel, and guard web
for frontend routes.
1'repository' => 'file', // from yaml file2 3// ...4 5'guards' => [6 'cp' => 'statamic', // the guard when using the cp7 'web' => 'web', // the guard when using Statamic frontend routes; non-statamic routes -> default guards in auth.php8],
config/auth.php
1'guards' => [ 2 'web' => [ 3 'driver' => 'session', 4 'provider' => 'users', 5 ], 6 'statamic' => [ 7 'driver' => 'session', 8 'provider' => 'statamic', 9 ]10 ],11 12// ...13 14'providers' => [15 'users' => [16 'driver' => 'eloquent',17 'model' => App\Models\User::class,18 ],19 'statamic' => [ 20 'driver' => 'statamic',21 ],22 23 // 'users' => [24 // 'driver' => 'database',25 // 'table' => 'users',26 // ],27],
Create admin user (super user)
php please:make user
and follow instructions. Define email, password, super user.
Now super user with access to control panel of Statamic is created and saved into yaml file.
Create front end users (no access to control panel)
For front end users, we need to make basic Laravel authentication (with Laravel Breeze, Jetstream or Fortify) with register, login form, which will save user to database. Now you can easily show content based on whether use is authenticated or just a guest.