File: /var/www/ivs.kaunokolegija.lt/laravel/app/Models/HonorsAndAward.php
<?php
namespace App\Models;
use App\Traits\Auditable;
use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class HonorsAndAward extends Model
{
use Auditable, HasFactory;
public $table = 'honors_and_awards';
protected $dates = [
'year',
'created_at',
'updated_at',
'deleted_at',
];
protected $fillable = [
'year',
'title',
'activity_type_desc',
'institution',
'country_id',
'created_at',
'updated_at',
'deleted_at',
];
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
public function scientists()
{
return $this->belongsToMany(Scientist::class);
}
public function getYearAttribute($value)
{
return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null;
}
public function setYearAttribute($value)
{
$this->attributes['year'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null;
}
public function country()
{
return $this->belongsTo(Country::class, 'country_id');
}
}