Skip to content

Commit

Permalink
feat: add publish date
Browse files Browse the repository at this point in the history
  • Loading branch information
daurensky committed Apr 16, 2024
1 parent 3a5537c commit b7ae50d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ return new class extends Migration
{
Schema::table('admin_kit_documents', function (Blueprint $table) {
$table->string('link')->nullable();
$table->timestamp('published_at')->nullable();
});
}

public function down()
{
Schema::table('admin_kit_documents', function (Blueprint $table) {
$table->dropColumn('link');
$table->dropColumn('published_at');
});
}
};
1 change: 1 addition & 0 deletions resources/lang/en/documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'file' => 'File',
'title' => 'Title',
'link' => 'Link',
'published_at' => 'Published At',

'created_at' => 'Создан',
'updated_at' => 'Обновлен',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/ru/documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'file' => 'Файл',
'title' => 'Заголовок',
'link' => 'Ссылка',
'published_at' => 'Дата публикации',

'created_at' => 'Создан',
'updated_at' => 'Обновлен',
Expand Down
2 changes: 1 addition & 1 deletion src/DocumentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function configurePackage(Package $package): void
->hasTranslations()
->hasMigrations([
'create_admin_kit_documents_table',
'add_link_column_to_admin_kit_documents_table',
'add_link_and_published_at_columns_to_admin_kit_documents_table',
])
->hasCommand(DocumentsCommand::class);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Document extends AbstractModel implements HasMedia
protected $fillable = [
'title',
'link',
'published_at',
];

protected $translatable = [
Expand All @@ -33,8 +34,8 @@ public function scopeYear(Builder $query, $year): Builder
$date = Carbon::createFromDate($year);

return $query
->where('created_at', '>=', $date->copy()->startOfYear())
->where('created_at', '<=', $date->copy()->endOfYear());
->where('published_at', '>=', $date->copy()->startOfYear())
->where('published_at', '<=', $date->copy()->endOfYear());
}

protected static function newFactory(): DocumentFactory
Expand Down
3 changes: 2 additions & 1 deletion src/UI/API/Controllers/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public function index(): PaginatedDataCollection
public function years(): JsonResponse
{
$years = Document::query()
->selectRaw('extract(year FROM created_at) AS year')
->selectRaw('extract(year FROM published_at) AS year')
->distinct()
->wherenotnull('published_at')
->orderBy('year', 'desc')
->pluck('year');

Expand Down
4 changes: 2 additions & 2 deletions src/UI/API/Data/DocumentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
public string $title,
public ?string $link,
public ?array $file,
public string $createdAt,
public ?string $publishedAt,
) {
}

Expand All @@ -30,7 +30,7 @@ public static function fromModel(Document $document): DocumentData
'mime' => $media->mime_type,
'size' => $media->size,
] : null,
createdAt: $document->created_at,
publishedAt: $document->published_at,

Check failure on line 33 in src/UI/API/Data/DocumentData.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property AdminKit\Documents\Models\Document::$published_at.

Check failure on line 33 in src/UI/API/Data/DocumentData.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property AdminKit\Documents\Models\Document::$published_at.
);
}
}
5 changes: 5 additions & 0 deletions src/UI/Filament/Resources/DocumentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static function form(Forms\Form $form): Forms\Form
->label(__('admin-kit-documents::documents.resource.title'))
->required($locale === app()->getLocale()),
])),
Forms\Components\DateTimePicker::make('published_at')
->label(__('admin-kit-documents::documents.resource.published_at'))
->default(now()),
])
->columns(1);
}
Expand All @@ -53,6 +56,8 @@ public static function table(Tables\Table $table): Tables\Table
->sortable(),
Tables\Columns\TextColumn::make('title')
->label(__('admin-kit-documents::documents.resource.title')),
Tables\Columns\TextColumn::make('published_at')
->label(__('admin-kit-documents::documents.resource.published_at')),
Tables\Columns\TextColumn::make('created_at')
->label(__('admin-kit-documents::documents.resource.created_at')),
])
Expand Down

0 comments on commit b7ae50d

Please sign in to comment.