Skip to content

Commit f90ed6b

Browse files
committed
✨ add published at to articles
1 parent 7b2eac9 commit f90ed6b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

app/Http/Livewire/Articles/Edit.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function mount(Article $article)
3030
$this->slug = $article->slug;
3131
$this->show_toc = $article->show_toc;
3232
$this->submitted_at = $article->submitted_at;
33+
$this->published_at = $article->published_at ? $article->publishedAt()->format('Y-m-d') : null;
3334
$this->canonical_url = $article->originalUrl();
3435
$this->preview = $article->getFirstMediaUrl('media');
3536
$this->associateTags = $this->tags_selected = old('tags', $article->tags()->pluck('id')->toArray());
@@ -66,6 +67,7 @@ public function save()
6667
'show_toc' => $this->show_toc,
6768
'canonical_url' => $this->canonical_url,
6869
'submitted_at' => $this->submitted_at,
70+
'published_at' => $this->published_at,
6971
]);
7072

7173
$this->article->syncTags($this->associateTags);

app/Models/Article.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ public function isNotDeclined(): bool
199199

200200
public function isPublished(): bool
201201
{
202-
return ! $this->isNotPublished();
202+
return ! $this->isNotPublished() && ($this->publishedAt() && $this->publishedAt()->lessThanOrEqualTo(now()));
203203
}
204204

205205
public function isNotPublished(): bool
206206
{
207-
return $this->isNotSubmitted() || $this->isNotApproved();
207+
return ($this->isNotSubmitted() || $this->isNotApproved()) && $this->published_at === null;
208208
}
209209

210210
public function isPinned(): bool

0 commit comments

Comments
 (0)