protected $isScopedToTenant not available when extending from package Resource Class

I cannot change the $isScopedToTenant variable when i use the following setup: Package has an Resource called:
class ScheduleResource extends Resource {}
class ScheduleResource extends Resource {}
in my application i override/extend this ScheduleResource:
use Package\Resource\ScheduleResource as BaseScheduleResource;

class ScheduleResource extends BaseScheduleResource {

protected static bool $isScopedToTenant = false; // <-- will not work
}
use Package\Resource\ScheduleResource as BaseScheduleResource;

class ScheduleResource extends BaseScheduleResource {

protected static bool $isScopedToTenant = false; // <-- will not work
}
i have to add in my package Resource class:
class ScheduleResource extends Resource {
public static bool $isScopedToTenant = true;
}
class ScheduleResource extends Resource {
public static bool $isScopedToTenant = true;
}
and then in my application ScheduleResource:
use Package\Resource\ScheduleResource as BaseScheduleResource;

class ScheduleResource extends BaseScheduleResource {
public static bool $isScopedToTenant = false; // <-- this WILL work
}
use Package\Resource\ScheduleResource as BaseScheduleResource;

class ScheduleResource extends BaseScheduleResource {
public static bool $isScopedToTenant = false; // <-- this WILL work
}
also this won't work:
class ScheduleResource extends BaseScheduleResource {

public function __construct() {
static::scopeToTenant(false); <-- will not work
}
}
class ScheduleResource extends BaseScheduleResource {

public function __construct() {
static::scopeToTenant(false); <-- will not work
}
}
Solution:
Okay i found the answer: I have to override this function in my class ScheduleResourse like so: ```...
Jump to solution
1 Reply
Solution
shenntek
shenntek10mo ago
Okay i found the answer: I have to override this function in my class ScheduleResourse like so:
class ScheduleResource extends BaseScheduleResource {

public function __construct() {
self::scopeToTenant(false);
}

public static function scopeToTenant(bool $condition = true): void
{
parent::$isScopedToTenant = $condition;
}
}
class ScheduleResource extends BaseScheduleResource {

public function __construct() {
self::scopeToTenant(false);
}

public static function scopeToTenant(bool $condition = true): void
{
parent::$isScopedToTenant = $condition;
}
}
Want results from more Discord servers?
Add your server