Skip to content

Commit c7ef826

Browse files
committed
Use boolean field
1 parent 2620279 commit c7ef826

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

app/Http/Requests/ArticleRequest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
use App\Rules\AuthorOwnsSeriesRule;
66
use App\Rules\HttpImageRule;
77
use App\User;
8+
use Illuminate\Http\Concerns\InteractsWithInput;
89

910
class ArticleRequest extends Request
1011
{
12+
use InteractsWithInput;
13+
1114
public function rules()
1215
{
1316
return [
@@ -17,7 +20,7 @@ public function rules()
1720
'tags.*' => 'exists:tags,id',
1821
'original_url' => 'url|nullable',
1922
'series' => ['nullable', new AuthorOwnsSeriesRule],
20-
'status' => ['required', 'in:draft,publish'],
23+
'published' => ['required', 'boolean'],
2124
];
2225
}
2326

@@ -53,6 +56,6 @@ public function originalUrl(): ?string
5356

5457
public function shouldBePublished(): bool
5558
{
56-
return $this->get('status') === 'publish';
59+
return $this->boolean('published');
5760
}
5861
}

resources/views/articles/_form.blade.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ class="text-green-darker"
8080

8181
<div class="flex justify-end items-center">
8282
<a href="{{ isset($article) ? route('articles.show', $article->slug()) : route('articles') }}" class="text-green-darker mr-4">Cancel</a>
83-
@if(isset($article) && $article->isPublished())
83+
@if (isset($article) && $article->isPublished())
8484
<button
8585
type="submit"
86-
name="status"
87-
value="publish"
86+
name="published"
87+
value="1"
8888
class="button button-primary"
8989
>
9090
Save changes
@@ -93,8 +93,8 @@ class="button button-primary"
9393
<span class="relative z-0 inline-flex shadow-sm" x-data="{ showDropdown: false }" @click.away="showDropdown = false">
9494
<button
9595
type="submit"
96-
name="status"
97-
value="draft"
96+
name="published"
97+
value="0"
9898
class="button button-primary button-dropdown-left relative inline-flex items-center focus:outline-none"
9999
>
100100
Save draft
@@ -114,8 +114,8 @@ class="button button-primary h-full button-dropdown-right relative inline-flex i
114114
<div class="py-1">
115115
<button
116116
type="submit"
117-
name="status"
118-
value="publish"
117+
name="published"
118+
value="1"
119119
class="block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900 w-full text-left"
120120
>
121121
Save and publish

tests/Feature/ArticleTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function users_can_create_an_article()
4949
'body' => 'This article will go into depth on working with database migrations.',
5050
'tags' => [$tag->id()],
5151
'series' => $series->id(),
52-
'status' => 'draft',
52+
'published' => '0',
5353
])
5454
->assertRedirectedTo('/articles/using-database-migrations')
5555
->assertSessionHas('success', 'Article successfully created!');
@@ -63,7 +63,7 @@ public function users_can_publish_an_article()
6363
$this->post('/articles', [
6464
'title' => 'Using database migrations',
6565
'body' => 'This article will go into depth on working with database migrations.',
66-
'status' => 'publish',
66+
'published' => '1',
6767
])
6868
->assertRedirectedTo('/articles/using-database-migrations')
6969
->followRedirects()
@@ -78,7 +78,7 @@ public function users_can_create_a_draft_article()
7878
$this->post('/articles', [
7979
'title' => 'Using database migrations',
8080
'body' => 'This article will go into depth on working with database migrations.',
81-
'status' => 'draft',
81+
'published' => '0',
8282
])
8383
->assertRedirectedTo('/articles/using-database-migrations')
8484
->followRedirects()
@@ -168,7 +168,7 @@ public function users_can_edit_an_article()
168168
'body' => 'This article will go into depth on working with database migrations.',
169169
'tags' => [$tag->id()],
170170
'series' => $series->id(),
171-
'status' => 'publish',
171+
'published' => '1',
172172
])
173173
->assertRedirectedTo('/articles/using-database-migrations')
174174
->assertSessionHas('success', 'Article successfully updated!');
@@ -190,7 +190,7 @@ public function users_can_publish_an_existing_article()
190190
$this->put('/articles/my-first-article', [
191191
'title' => 'Using database migrations',
192192
'body' => 'This article will go into depth on working with database migrations.',
193-
'status' => 'publish',
193+
'published' => '1',
194194
])
195195
->assertRedirectedTo('/articles/using-database-migrations')
196196
->followRedirects()
@@ -213,7 +213,7 @@ public function users_can_unpublish_an_existing_article()
213213
$this->put('/articles/my-first-article', [
214214
'title' => 'Using database migrations',
215215
'body' => 'This article will go into depth on working with database migrations.',
216-
'status' => 'draft',
216+
'published' => '0',
217217
])
218218
->assertRedirectedTo('/articles/using-database-migrations')
219219
->followRedirects()
@@ -323,7 +323,11 @@ public function canonical_urls_are_rendered()
323323
/** @test */
324324
public function custom_canonical_urls_are_rendered()
325325
{
326-
factory(Article::class)->create(['slug' => 'my-first-article', 'original_url' => 'https://joedixon.co.uk/my-first-article', 'published_at' => now()]);
326+
factory(Article::class)->create([
327+
'slug' => 'my-first-article',
328+
'original_url' => 'https://joedixon.co.uk/my-first-article',
329+
'published_at' => now()
330+
]);
327331

328332
$this->get('/articles/my-first-article')
329333
->see('<link rel="canonical" href="https://joedixon.co.uk/my-first-article" />');

0 commit comments

Comments
 (0)