Files
exchange-2.0/app/Models/SegmentConstant.php

52 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class SegmentConstant
* @package App\Models
*
* @property \App\Models\Segment segment_id
* @property string detail
*/
class SegmentConstant extends AbstractModel
{
use SoftDeletes;
protected $table = 'segment_constants';
protected $dates = ['deleted_at'];
// protected $casts = [
// 'detail' => 'array',
// ];
public function getDetailAttribute($value)
{
return $value ? json_decode($value) : [];
}
/**
* @return BelongsTo
*/
public function segment(): BelongsTo
{
return $this->BelongsTo(Segment::class, 'segment_id', 'id');
}
/**
* @return mixed
*/
public function service(){
return $this->hasOne(ServiceType::class, 'id', 'detail->id')
->whereIn('reference', [SegmentConstants::SERVICE_TYPE, SegmentConstants::CUSTOM_SERVICE_TYPE]);
}
}