Files
InvoiceShelf/app/Models/CustomFieldValue.php
Darko Gjorgjijoski 0fa1aac748 Add return types, typed parameters, and PHPDoc to all model methods
Modernize all 16 models with missing type declarations:
- Return types on ~87 methods (string, bool, void, array, mixed, etc.)
- Typed parameters where missing
- PHPDoc blocks on non-obvious methods explaining their purpose

Models updated: Invoice, Estimate, Payment, User, Company, Customer,
RecurringInvoice, Setting, CompanySetting, FileDisk, Transaction,
EmailLog, ExchangeRateLog, PaymentMethod, CustomField, CustomFieldValue.
2026-04-03 20:46:26 +02:00

58 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class CustomFieldValue extends Model
{
use HasFactory;
protected $dates = [
'date_answer',
'date_time_answer',
];
protected $guarded = [
'id',
];
protected $appends = [
'defaultAnswer',
];
public function setTimeAnswerAttribute(mixed $value): void
{
if ($value && $value != null) {
$this->attributes['time_answer'] = date('H:i:s', strtotime($value));
} else {
$this->attributes['time_answer'] = null;
}
}
public function getDefaultAnswerAttribute()
{
$value_type = getCustomFieldValueKey($this->type);
return $this->$value_type;
}
public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
public function customField(): BelongsTo
{
return $this->belongsTo(CustomField::class);
}
public function customFieldValuable(): MorphTo
{
return $this->morphTo();
}
}