Move category/category_name product::class methods into __get(), no functional changes
This commit is contained in:
@@ -10,10 +10,30 @@ use Leenooks\Traits\ScopeActive;
|
||||
use App\Models\{Invoice, Supplier, SupplierDetail};
|
||||
use App\Traits\SiteID;
|
||||
|
||||
/**
|
||||
* Class Supplier\Type
|
||||
*
|
||||
* Attributes for supplier types:
|
||||
* + category : This will return the category of the product (eg: domain, hosting, etc), based on the class, which is the basis for all other logic of these types.
|
||||
* + category_name : A friendly name that can override category
|
||||
*/
|
||||
|
||||
abstract class Type extends Model
|
||||
{
|
||||
use SiteID,ScopeActive;
|
||||
|
||||
protected const category_name = NULL;
|
||||
|
||||
public function __get($key): mixed
|
||||
{
|
||||
return match ($key) {
|
||||
'category' => (new \ReflectionClass($this))->getShortName(),
|
||||
'category_name' => static::category_name ?: $this->category,
|
||||
|
||||
default => parent::__get($key),
|
||||
};
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
/**
|
||||
@@ -33,27 +53,6 @@ abstract class Type extends Model
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
/**
|
||||
* This will return the category of the product (eg: domain, hosting, etc) which is the basis for all
|
||||
* other logic of these types.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final public function getCategoryAttribute(): string
|
||||
{
|
||||
return strtolower((new \ReflectionClass($this))->getShortName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a friendly name for this product, used for display
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final public function getCategoryNameAttribute(): string
|
||||
{
|
||||
return static::category_name;
|
||||
}
|
||||
|
||||
final public function getContractTermAttribute(?int $val): int
|
||||
{
|
||||
return $val ?: 1;
|
||||
|
Reference in New Issue
Block a user