first commit
This commit is contained in:
69
app/Models/ChecklistItem.php
Normal file
69
app/Models/ChecklistItem.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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\HasMany;
|
||||
|
||||
class ChecklistItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const INPUT_TYPES = [
|
||||
'number' => 'Nombor',
|
||||
'text' => 'Teks',
|
||||
'textarea' => 'Teks Panjang',
|
||||
'select' => 'Senarai Pilihan',
|
||||
'checkbox' => 'Kotak Semak',
|
||||
'file_reference' => 'Rujukan Fail',
|
||||
'calculated' => 'Dikira Automatik',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'checklist_section_id',
|
||||
'checklist_scope_id',
|
||||
'code',
|
||||
'formula_token',
|
||||
'label',
|
||||
'description',
|
||||
'input_type',
|
||||
'options',
|
||||
'unit',
|
||||
'is_required',
|
||||
'is_calculated',
|
||||
'formula',
|
||||
'order',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'options' => 'array',
|
||||
'is_required' => 'boolean',
|
||||
'is_calculated' => 'boolean',
|
||||
'order' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function section(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ChecklistSection::class, 'checklist_section_id');
|
||||
}
|
||||
|
||||
public function scope(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ChecklistScope::class, 'checklist_scope_id');
|
||||
}
|
||||
|
||||
public function answers(): HasMany
|
||||
{
|
||||
return $this->hasMany(SubmissionAnswer::class);
|
||||
}
|
||||
|
||||
public function isNumeric(): bool
|
||||
{
|
||||
return in_array($this->input_type, ['number', 'calculated'], true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user