39 lines
824 B
PHP
39 lines
824 B
PHP
<?php
|
|
|
|
namespace Modules\PMS\Models;
|
|
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Comment extends Model
|
|
{
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected $fillable = ['content', 'comment_by'];
|
|
|
|
// protected $casts = [
|
|
// 'created_at' => 'datetime',
|
|
// ];
|
|
|
|
protected function createdAtFormatted(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value, $attributes) => Carbon::parse($attributes['created_at'])->format('d, M Y H:i'),
|
|
);
|
|
}
|
|
|
|
public function comments()
|
|
{
|
|
return $this->morphMany(Comment::class, 'commentable');
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'comment_by');
|
|
}
|
|
}
|