I recently started using Eloquent.
When I used PHP Active Record, there was a nice function that checked if a record was loaded from the database or is a new instan
We can use $appends
on model if you will use it many times.. for example to check if the newly created comment is edited after created.
class Comment extends Model
{
protected $appends = ['is_edited'];
public function getIsEditedAttribute()
{
return $this->attributes['is_edited'] = ($this->created_at != $this->updated_at) ? true : false;
}
}
You can use it like
$comment = Comment::findOrFail(1);
if($comment->is_edited){
// write your logic here
}