/home/mip/mip/app/Modules/Client/Models/Posts/Posts.php
<?php
namespace QxCMS\Modules\Client\Models\Posts;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class Posts extends Model
{
protected $connection = 'client';
protected $table = 'posts';
public $module_id = 9;
protected $guarded = [];
protected $appends = ['hashid'];
public function getHashidAttribute()
{
return hashid($this->id);
}
public function setPublishedAtAttribute($value)
{
if($value <> '') {
$dateformats = getDateFormatConfig('set');
return $this->attributes['published_at'] = Carbon::createFromFormat($dateformats['php'], $value)->format('Y-m-d');
}
return $this->attributes['published_at'] = '0000-00-00';
}
public function getPublishedAtAttribute($value)
{
if($value <> '0000-00-00') {
$dateformats = getDateFormatConfig('get');
return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
}
return;
}
public function formPublishedAtAttribute($value)
{
if($value <> '0000-00-00') {
$dateformats = getDateFormatConfig('form');
return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
}
return;
}
public function setExpiredAtAttribute($value)
{
if($value <> '') {
$dateformats = getDateFormatConfig('set');
return $this->attributes['expired_at'] = Carbon::createFromFormat($dateformats['php'], $value)->format('Y-m-d');
}
return $this->attributes['expired_at'] = '0000-00-00';
}
public function getExpiredAtAttribute($value)
{
if($value <> '0000-00-00') {
$dateformats = getDateFormatConfig('get');
return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
}
return;
}
public function formExpiredAtAttribute($value)
{
if($value <> '0000-00-00') {
$dateformats = getDateFormatConfig('form');
return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
}
return;
}
public function getCreatedAtAttribute($value)
{
return Carbon::parse($value)->format('M d, Y @ h:i A');
}
public function category()
{
return $this->belongsTo('QxCMS\Modules\Client\Models\Posts\PostCategory', 'posts_category_id');
}
public function author()
{
return $this->belongsTo('QxCMS\Modules\Likod\Models\Clients\User', 'author_id');
}
public function subPages()
{
return $this->hasMany('QxCMS\Modules\Client\Models\Pages\Pages', 'post_parent_id');
}
}