79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use App\Constant\Constant;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use App\Models\Traits\Post\Attributes\PostAttributes;
|
||
|
|
use App\Models\Traits\Post\Relationships\PostRelationships;
|
||
|
|
use App\Traits\HasKarmaPoint;
|
||
|
|
|
||
|
|
class Post extends Model
|
||
|
|
{
|
||
|
|
use HasFactory, PostRelationships, PostAttributes, HasKarmaPoint;
|
||
|
|
|
||
|
|
/*
|
||
|
|
* Pseudo-fields that get added to the models when the models are exported to json.
|
||
|
|
*/
|
||
|
|
protected $appends = ['created_ago', 'is_friends', 'is_liked', 'post_type', 'mentions'];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Attributes that are mass assignable
|
||
|
|
*
|
||
|
|
* @var array
|
||
|
|
*/
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'user_id',
|
||
|
|
'privacy',
|
||
|
|
'category_id',
|
||
|
|
'location',
|
||
|
|
'latitude',
|
||
|
|
'longitude',
|
||
|
|
'status',
|
||
|
|
'description',
|
||
|
|
'created_at',
|
||
|
|
'updated_at',
|
||
|
|
'created_by',
|
||
|
|
'updated_by',
|
||
|
|
'type_id',
|
||
|
|
'type',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $guarded = [
|
||
|
|
'id'
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
||
|
|
*/
|
||
|
|
public function scopeIsPublish()
|
||
|
|
{
|
||
|
|
return $this->query()->where('status', Constant::POST_PUBLISH);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
||
|
|
*/
|
||
|
|
public function scopeIsDraft()
|
||
|
|
{
|
||
|
|
return $this->query()->where('status', Constant::POST_DRAFT);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns model in days since created_at.
|
||
|
|
*/
|
||
|
|
public function getCreatedAgoAttribute() {
|
||
|
|
return $this->created_at->diffForHumans();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* add points for for registration.
|
||
|
|
*/
|
||
|
|
public function addPoints()
|
||
|
|
{
|
||
|
|
return $this->morphMany(KarmaPointsTransaction::class, 'pointable');
|
||
|
|
}
|
||
|
|
}
|