Skip to content

Commit

Permalink
published at attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
SethSharp committed Apr 2, 2024
1 parent c676aa3 commit 0db6957
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Models/Blog/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class Blog extends Model

protected $guarded = [];

protected $appends = ['cover'];
protected $appends = [
'cover',
'published_at_for_humans'
];

protected $casts = [
'is_draft' => 'bool',
Expand Down Expand Up @@ -119,4 +122,11 @@ public function cover(): Attribute
get: fn() => $this?->cover_image ? Storage::disk('s3')->url($this->cover_image) : null
);
}

public function publishedAtForHumans(): Attribute
{
return Attribute::make(
get: fn() => $this?->published_at ? $this->published_at->diffForHumans() : 'not published yet'
);
}
}

0 comments on commit 0db6957

Please sign in to comment.