Skip to content

Commit dceb83a

Browse files
committed
Improve article management
1 parent 2b18432 commit dceb83a

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

app/Filament/Resources/ArticleResource.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use App\Filament\Resources\ArticleResource\Actions\PreviewAction;
66
use App\Filament\Resources\ArticleResource\Actions\PublishAction;
7-
use App\Filament\Resources\ArticleResource\Actions\ScheduleAction;
87
use App\Filament\Resources\ArticleResource\Actions\UnpublishAction;
98
use App\Filament\Resources\ArticleResource\Pages;
109
use App\Models\Article;
@@ -80,10 +79,6 @@ public static function table(Table $table): Table
8079
->searchable()
8180
->sortable(),
8281

83-
TextColumn::make('excerpt')
84-
->searchable()
85-
->limit(50),
86-
8782
TextColumn::make('author.name')
8883
->label('Author')
8984
->searchable()
@@ -106,7 +101,6 @@ public static function table(Table $table): Table
106101
Tables\Actions\EditAction::make()->url(fn ($record) => static::getUrl('edit', ['record' => $record->id])),
107102
UnpublishAction::make('unpublish'),
108103
PublishAction::make('publish'),
109-
ScheduleAction::make('schedule'),
110104
]),
111105
])
112106
->bulkActions([

app/Filament/Resources/ArticleResource/Actions/PublishAction.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace App\Filament\Resources\ArticleResource\Actions;
44

55
use App\Models\Article;
6+
use Filament\Forms\Components\DateTimePicker;
7+
use Filament\Forms\Components\Radio;
68
use Filament\Tables\Actions\Action;
9+
use Illuminate\Support\Carbon;
710

811
class PublishAction extends Action
912
{
@@ -12,8 +15,31 @@ protected function setUp(): void
1215
$this
1316
->label('Publish')
1417
->icon('heroicon-o-newspaper')
15-
->action(fn (Article $article) => $article->publish())
1618
->visible(fn (Article $article) => ! $article->isPublished())
17-
->requiresConfirmation();
19+
->form([
20+
Radio::make('publish_type')
21+
->label('Publish Options')
22+
->options([
23+
'now' => 'Publish Now',
24+
'schedule' => 'Schedule for Later',
25+
])
26+
->default('now')
27+
->live()
28+
->required(),
29+
DateTimePicker::make('published_at')
30+
->label('Published At')
31+
->displayFormat('M j, Y H:i')
32+
->seconds(false)
33+
->afterOrEqual('now')
34+
->visible(fn ($get) => $get('publish_type') === 'schedule')
35+
->required(fn ($get) => $get('publish_type') === 'schedule'),
36+
])
37+
->action(function (Article $article, array $data) {
38+
if ($data['publish_type'] === 'now') {
39+
$article->publish();
40+
} else {
41+
$article->publish(Carbon::parse($data['published_at']));
42+
}
43+
});
1844
}
1945
}

app/Filament/Resources/ArticleResource/Pages/EditArticle.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,40 @@ protected function afterSave(): void
2626
protected function getHeaderActions(): array
2727
{
2828
return [
29+
Actions\Action::make('preview')
30+
->label('Preview')
31+
->icon('heroicon-o-eye')
32+
->url(fn () => route('article', $this->record))
33+
->openUrlInNewTab(),
34+
Actions\Action::make('publish')
35+
->label('Publish')
36+
->icon('heroicon-o-newspaper')
37+
->visible(fn () => ! $this->record->isPublished())
38+
->form([
39+
\Filament\Forms\Components\Radio::make('publish_type')
40+
->label('Publish Options')
41+
->options([
42+
'now' => 'Publish Now',
43+
'schedule' => 'Schedule for Later',
44+
])
45+
->default('now')
46+
->live()
47+
->required(),
48+
\Filament\Forms\Components\DateTimePicker::make('published_at')
49+
->label('Published At')
50+
->displayFormat('M j, Y H:i')
51+
->seconds(false)
52+
->afterOrEqual('now')
53+
->visible(fn ($get) => $get('publish_type') === 'schedule')
54+
->required(fn ($get) => $get('publish_type') === 'schedule'),
55+
])
56+
->action(function (array $data) {
57+
if ($data['publish_type'] === 'now') {
58+
$this->record->publish();
59+
} else {
60+
$this->record->publish(\Illuminate\Support\Carbon::parse($data['published_at']));
61+
}
62+
}),
2963
Actions\DeleteAction::make(),
3064
];
3165
}

0 commit comments

Comments
 (0)