I have created a model called Author which extends the RainLab\User\Models\User In the boot function extending form fields I only wish to display the tab fields if the user belongs to a specific RainLab\User\Models\UserGroup .
In this instance the group I want has the following fields
id =4, name = Author, code = author
I can achieve this by using the code below but was wondering if there was a better way of doing this.
UsersController::extendFormFields(function($form, $model, $context) {
if(!$model instanceof UserModel)
return;
if(!$model->exists)
return;
if(!AuthorModel::isAuthor($model))
return;
The function below is what I am using to check if user is a member of the author group .
public static function isAuthor($user)
{
return DB::table('users_groups')->where('user_id',$user->id)->where('user_group_id', 4 )->first();
}
Last updated