Configuration
- Who’s a Member?
- Getting started
- Using Laravel middleware to redirect unauthenticated users?
- Using the Eloquent user driver?
Who’s a Member?
This addon defines a member as any user who has the roles and groups listed in the statamic.users.new_user_roles
and statamic.users.new_user_groups
config variables, as these are the roles and groups Statamic assigns to users who register themselves through the user registration form.
Getting started
1. Configure Statamic's new user settings
The first thing you'll need to do is set Statamic's new user settings to the roles/groups you want members to have. You can specify any roles/groups you like, but for a simple setup I would recommend a single group called members
.
To do this you'll need to create a members
group. You can either do this through the control panel's groups editor, or in the resources/users/groups.yaml
file directly:
members:title: Members
members:title: Members
Then open config/statamic/users.php
and update the new_user_groups
setting:
'new_user_groups' => ['members',],
'new_user_groups' => ['members',],
2. Publish the Memberbox config
Next you should publish the Memberbox config:
php please vendor:publish --tag=statamic-memberbox-config
php please vendor:publish --tag=statamic-memberbox-config
Then open config/statamic/memberbox.php
to make any changes. Check the customisation page for further details.
3. Grant control panel permissions
To give control panel users access to the members section you will need to grant them the appropriate permissions (super admins always have access to everything). You can either do this through the control panel's permissions editor, or in the resources/users/roles.yaml
file directly:
admin:title: Adminpermissions:- 'mb view members'- 'mb edit members'- 'mb create members'
admin:title: Adminpermissions:- 'mb view members'- 'mb edit members'- 'mb create members'
Changing member passwords and deleting members is currently restricted to users with the change passwords
and delete users
permissions.
Using Laravel middleware to redirect unauthenticated users?
If you're using Laravel's auth middleware to redirect unauthenticated users to a login page, and want to use Memberbox's login route for that, you'll need to update it with the Memberbox route name:
// /app/Http/Middleware/Authenticate.phpprotected function redirectTo($request){if (! $request->expectsJson()) {return route('statamic-memberbox.login');}}
// /app/Http/Middleware/Authenticate.phpprotected function redirectTo($request){if (! $request->expectsJson()) {return route('statamic-memberbox.login');}}
Using the Eloquent user driver?
If you're using the Eloquent user driver you need to ensure the roles and groups relationships are defined on your user model. For example:
// /app/Models/User.phpclass User extends Authenticatable{// ...public function roles(){return $this->hasMany(RoleUser::class);}public function groups(){return $this->hasMany(GroupUser::class);}}// /app/Models/GroupUser.phpclass GroupUser extends Model{protected $table = 'group_user';}// /app/Models/RoleUser.phpclass RoleUser extends Model{protected $table = 'role_user';}
// /app/Models/User.phpclass User extends Authenticatable{// ...public function roles(){return $this->hasMany(RoleUser::class);}public function groups(){return $this->hasMany(GroupUser::class);}}// /app/Models/GroupUser.phpclass GroupUser extends Model{protected $table = 'group_user';}// /app/Models/RoleUser.phpclass RoleUser extends Model{protected $table = 'role_user';}