Skip to content

Commit 722050c

Browse files
committed
Allow scheduled articles to be viewed with link
1 parent 71bff5e commit 722050c

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

app/Http/Controllers/ShowBlogController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function index()
2020

2121
public function show(Article $article)
2222
{
23-
abort_unless($article->isPublished() || auth()->user()?->isAdmin(), 404);
23+
abort_unless($article->isPublished() || $article->isScheduled() || auth()->user()?->isAdmin(), 404);
2424

2525
// Set SEO metadata for the article
2626
SEOTools::setTitle($article->title.' - Blog');

app/Models/Article.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function isPublished(): bool
6262
return $this->published_at && $this->published_at->isPast();
6363
}
6464

65+
public function isScheduled(): bool
66+
{
67+
return $this->published_at && $this->published_at->isFuture();
68+
}
69+
6570
public function publish(?DateTime $on = null)
6671
{
6772
if (! $on) {

tests/Feature/BlogTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ public function published_articles_are_visitable()
6969
}
7070

7171
#[Test]
72-
public function scheduled_articles_return_a_404()
72+
public function scheduled_articles_are_visitable_via_direct_link()
7373
{
7474
$article = Article::factory()->scheduled()->create();
7575

7676
$this->get(route('article', $article))
77-
->assertStatus(404);
77+
->assertOk();
7878
}
7979

8080
#[Test]

0 commit comments

Comments
 (0)