56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class MasterParameter extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'parameter_code',
|
|
'parameter_name',
|
|
'default_value',
|
|
'unit',
|
|
'description',
|
|
];
|
|
|
|
protected $casts = [
|
|
'default_value' => 'decimal:6',
|
|
];
|
|
|
|
/**
|
|
* Relationship to FormulaParameter
|
|
*/
|
|
public function formulaParameters()
|
|
{
|
|
return $this->hasMany(FormulaParameter::class, 'parameter_id');
|
|
}
|
|
|
|
/**
|
|
* Relationship to MasterFormula through FormulaParameter
|
|
*/
|
|
public function formulas()
|
|
{
|
|
return $this->belongsToMany(MasterFormula::class, 'formula_parameters', 'parameter_id', 'formula_id');
|
|
}
|
|
|
|
/**
|
|
* Scope untuk mencari berdasarkan parameter code
|
|
*/
|
|
public function scopeByCode($query, $code)
|
|
{
|
|
return $query->where('parameter_code', $code);
|
|
}
|
|
|
|
/**
|
|
* Method untuk mendapatkan nilai parameter dengan fallback ke default
|
|
*/
|
|
public function getValue($customValue = null)
|
|
{
|
|
return $customValue !== null ? $customValue : $this->default_value;
|
|
}
|
|
}
|