Files
crater/app/Models/CustomFieldValue.php
Mohit Panjwani 082d5cacf2 v5.0.0 update
2021-11-30 18:58:19 +05:30

67 lines
1.5 KiB
PHP

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