Feuerwehr-eppingen/app/Models/BaseModel.php
2022-08-17 21:20:44 +02:00

78 lines
1.6 KiB
PHP
Executable File

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class BaseModel extends Model
{
use SoftDeletes;
protected $modelType = "BASE";
public $timestamps = true;
public $hasFiles = true;
public $hasPublications = true;
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];
public function getIsPostAttribute()
{
return ($this->modelType == 'POST') ? true : false;
}
public function getIsTagAttribute()
{
return ($this->modelType == 'TAG') ? true : false;
}
public function getHasFilesAttribute()
{
return $this->hasFiles;
}
public function getHasPublicationsAttribute()
{
return $this->hasPublications;
}
public function user()
{
return $this->HasOne('App\Models\User', 'id', 'user_id');
}
public function getUpdatedAttribute($value)
{
return \Carbon\Carbon::createFromTimestamp(strtotime($this->updated_at))->diffForHumans();
}
public function getCreatedAttribute($value)
{
return \Carbon\Carbon::createFromTimestamp(strtotime($this->created_at))->diffForHumans();
}
public function getDeletedAttribute($value)
{
if(empty($value))
{
return $value;
}
else
{
return \Carbon\Carbon::createFromTimestamp(strtotime($this->deleted_at))->diffForHumans();
}
}
public function disableTimestamps()
{
$this->timestamps = false;
}
public function enableTimestamps()
{
$this->timestamps = true;
}
}