In my Laravel task scheduler, I am trying to make an object of a model and call a function of that model. Inside the function I am trying to access a model property using $this keyword. It throws an exception indicating that the property is not defined. Please note that the same code is working perfectly in a normal controller and the exception occurs only when I run it by task scheduler.
Here is a simplified version of my code in kernel.php
$schedule->call(function () {
   $group_set_id = 8345;       
   $group_set = new GroupCategory(['group_set_id' => $group_set_id]);
   $group_set->changeSelfSignup(true);                
}
Here is what I have in model:
class GroupCategory extends Model
{
protected $fillable = [
    'id', 'group_set_id', 'course_ids', 'course_names', 'section_ids', 'section_names', 'auto_update'
];
protected $attributes = [
    'id',
    'group_set_id' => '',
    'name' => '',
    'role' => '',
    'self_signup' => null,
    'auto_leader' => null,
    'context_type' => '',
    'account_id' => '',
    'group_limit' => null,
    'sis_group_category_id' => null,
    'sis_import_id' => null,
    'progress' => null
];
protected $primaryKey = 'id';
public $timestamps = true;
public function getGroupCategoryGroups()
{
    $type = 'get';
    $form_params = ['include' => 'email'];
    $url = APIUtility::getGroupCategoryGroupsURL($this->group_set_id) . '?per_page=100';
    return APIUtility::getResponse($type, $url, $form_params);
}
public function createGroup(string $group_name)
{
    $type = 'post';
    $form_params = ['name' => $group_name];
    $url = APIUtility::createGroupURL($this->group_set_id);
    return APIUtility::getResponse($type, $url, $form_params);
}
public function __construct(array $attributes = [])
{
    parent::__construct($attributes);
}
protected $primaryKey = 'id';
public function changeSelfSignup(bool $is_self_signup_allowed)
{
    $type = 'put';
    $form_params = ['self_signup' => $is_self_signup_allowed ? 'enabled' : 'disabled'];
    $url = APIUtility::getSelfSignupURL($this->group_set_id);
    return APIUtility::getResponse($type, $url, $form_params);
}
Here is the exception I am getting:
ErrorException: Undefined variable: group_set_id in /var/www/utagt/app/GroupCategory.php:78
Any idea would be appreciated.