Files
aso/app/Models/Practice.php
2022-10-28 15:03:21 +07:00

42 lines
854 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Practice extends Model
{
use HasFactory;
protected $fillable = [
'practitioner_role_id',
'service_code',
'active',
'created_by',
'updated_by',
'deleted_by'
];
public function getPriceAttribute()
{
return $this->prices->where('priceable_id', $this->id)->max('price_net');
}
public function getPricesGroupOneAttribute()
{
$orgPrices = [];
foreach ($this->prices->where('price_group_id', 1) as $price) {
$orgPrices[$this->service_code] = $price->price_net;
}
return $orgPrices;
}
public function prices()
{
return $this->morphMany(Price::class, 'priceable');
}
}