Move some product product\supplier and product\type::class methods into __get(), no functional changes

This commit is contained in:
2025-05-22 18:17:27 +10:00
parent 72b11172c8
commit 251aefa947
11 changed files with 46 additions and 77 deletions

View File

@@ -16,11 +16,13 @@ final class Domain extends Type
// The model of the product that is supplied by this model
const ProductModel = ProductDomain::class;
/* INTERFACES */
public function getNameAttribute(): string
public function __get($key): mixed
{
return sprintf('%s: %s',$this->product_id,$this->tld->name);
return match ($key) {
'name' => sprintf('%s: %s',$this->product_id,$this->tld->name),
default => parent::__get($key),
};
}
/* STATIC */

View File

@@ -3,11 +3,10 @@
namespace App\Models\Supplier;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Validation\Rule;
use Leenooks\Traits\ScopeActive;
use App\Models\{Invoice, Supplier, SupplierDetail};
use App\Models\{Supplier,SupplierDetail};
use App\Traits\SiteID;
/**
@@ -31,6 +30,12 @@ abstract class Type extends Model
'category_lc' => strtolower($this->category),
'category_name' => static::category_name ?: $this->category,
'min_cost' => $this->setup_cost+$this->base_cost*$this->contract_term,
'name' => $this->product_id ?: 'Supplier PID Unknown',
'name_long' => $this->product_desc ?: 'Supplier NAME Unknown',
'supplier' => $this->supplier_detail->supplier,
default => parent::__get($key),
};
}
@@ -59,31 +64,11 @@ abstract class Type extends Model
return $val ?: 1;
}
public function getMinCostAttribute(): float
{
return $this->setup_cost+$this->base_cost*$this->contract_term;
}
public function getNameAttribute(): string
{
return $this->product_id ?: 'Supplier PID Unknown';
}
public function getNameLongAttribute(): string
{
return $this->product_desc ?: 'Supplier NAME Unknown';
}
public function getSetupCostAttribute(?float $val): float
{
return $val ?: 0;
}
public function getSupplierAttribute(): Model
{
return $this->supplier_detail->supplier;
}
public function validation(): array
{
return [