mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
43 lines
1.6 KiB
PHP
Executable File
43 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Streamline\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use OwenIt\Auditing\Contracts\Auditable;
|
|
use Streamline\Models\Subcounty;
|
|
use Streamline\Models\County;
|
|
use Streamline\Models\District;
|
|
|
|
class Parish extends Model implements Auditable {
|
|
// use laravel-auditing to track database changes
|
|
use \OwenIt\Auditing\Auditable;
|
|
|
|
// use for soft deletes
|
|
use SoftDeletes;
|
|
|
|
// mutate to dates
|
|
protected $dates = ['deleted_at'];
|
|
|
|
/* added this to allow plucking the name + district at once when making a dropdown */
|
|
public function getNameWithSubcountyAttribute($value)
|
|
{
|
|
$subcounty_details = Subcounty::find($this->subcounty_id);
|
|
if (is_null($subcounty_details)) {
|
|
return ucfirst($this->name) . ' '.'(Subcounty: N/A, County: N/A, District: N/A)';
|
|
}
|
|
|
|
$county_details = County::find($subcounty_details->county_id);
|
|
if (is_null($county_details)) {
|
|
return ucfirst($this->name) . ' '.'(Subcounty:'.ucfirst($subcounty_details->name).', County: N/A, District: N/A)';
|
|
}
|
|
|
|
$district_details = District::find($county_details->district_id);
|
|
if (is_null($district_details)) {
|
|
return ucfirst($this->name) . ' '.'(Subcounty:'.ucfirst($subcounty_details->name).', County:'. ucfirst($county_details->name).', District: N/A)';
|
|
}
|
|
|
|
return ucfirst($this->name) . ' '.'(Subcounty:'.ucfirst($subcounty_details->name).', County:'. ucfirst($county_details->name).', District:'.ucfirst($district_details->name).')';
|
|
}
|
|
}
|