I am trying to wrap my head around octobercms group and permission. I added a great plugin on permission and role that is straight forward and easy to implement on page/users but my question is do I have to add all users to group manually from the backend like one by one?
I created a new plugin and in the Plugin.php file I have this, use Event; //on the top of the file
I have this in its boot method to add users to the group with code seller
on registration.
public function boot()
{
Event::listen('rainlab.user.register', function($user){
$group =
\Rainlab\User\Models\UserGroup::where('code', 'seller')->first();
$user->groups()->add($group);
$user->save();
});
Doesn't seem to work. what am I missing in all of these?
plugin.php file
<?php namespace Corymillz\Newplug;
use System\Classes\PluginBase;
use Event;
class Plugin extends PluginBase
{
public function registerComponents()
{
}
public function registerSettings()
{
}
public function boot()
{
Event::listen('rainlab.user.register', function($user,$postdata){
$group = \Rainlab\User\Models\UserGroup::where('code', 'seller')->first();
$user->groups = $group->id;
$user->save();
});
}
}
just change your code like that.
Event::listen('rainlab.user.register', function($user,$postdata){
$group = \Rainlab\User\Models\UserGroup::where('code', 'seller')->first();
$user->groups = $group->id;
$user->save();
});