/home/mip/mip/app/Modules/Client/Models/Subject/Subject.php
<?php
namespace QxCMS\Modules\Client\Models\Subject;
use Illuminate\Database\Eloquent\Model;
use Collective\Html\Eloquent\FormAccessible;
use \Carbon\Carbon;
class Subject extends Model
{
use FormAccessible;
protected $connection = 'client';
protected $table = 'survey_subjects';
public $module_id = 6;
/*
* The attributes that are mass assignable.
*
* @var array
*/
protected $guarded = [];
protected $appends = ['hashid'];
public function getHashidAttribute()
{
return hashid($this->id);
}
// Interview Date Overrides
public function setInterviewDateAttribute($value)
{
if($value <> '') {
$dateformats = getDateFormatConfig('set');
return $this->attributes['interview_date'] = Carbon::createFromFormat($dateformats['php'], $value)->format('Y-m-d');
}
return $this->attributes['interview_date'] = '0000-00-00';
}
public function getInterviewDateAttribute($value)
{
if($value <> '0000-00-00') {
$dateformats = getDateFormatConfig('get');
return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
}
return;
}
public function formInterviewDateAttribute($value)
{
if($value <> '0000-00-00') {
$dateformats = getDateFormatConfig('form');
return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
}
return;
}
public function setCompletionDateAttribute($value)
{
if($value <> '') {
$dateformats = getDateFormatConfig('set');
return $this->attributes['completion_date'] = Carbon::createFromFormat($dateformats['php'], $value)->format('Y-m-d');
}
return $this->attributes['completion_date'] = '0000-00-00';
}
public function getCompletionDateAttribute($value)
{
if($value <> '0000-00-00') {
$dateformats = getDateFormatConfig('get');
return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
}
return;
}
public function formCompletionDateAttribute($value)
{
if($value <> '0000-00-00') {
$dateformats = getDateFormatConfig('form');
return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
}
return;
}
/*
* Model Custom Functions
*/
public function principal()
{
return $this->belongsTo('QxCMS\Modules\Client\Models\Principals\Principal', 'principal_id');
}
public function template()
{
return $this->belongsTo('QxCMS\Modules\Client\Models\Questionnaire\Template', 'template_id');
}
public function fieldOfficer()
{
return $this->belongsTo('QxCMS\Modules\Likod\Models\Clients\User', 'field_officer_assigned');
}
public function editor()
{
return $this->belongsTo('QxCMS\Modules\Likod\Models\Clients\User', 'editor_assigned');
}
}