Skip to content

Commit

Permalink
feat: add upload link
Browse files Browse the repository at this point in the history
  • Loading branch information
daurensky committed Apr 16, 2024
1 parent e5d4c0d commit 3a5537c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
{
Schema::table('admin_kit_documents', function (Blueprint $table) {
$table->string('link')->nullable();
});
}

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

'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 @@ -8,6 +8,7 @@
'id' => 'ID',
'file' => 'Файл',
'title' => 'Заголовок',
'link' => 'Ссылка',

'created_at' => 'Создан',
'updated_at' => 'Обновлен',
Expand Down
5 changes: 4 additions & 1 deletion src/DocumentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public function configurePackage(Package $package): void
->hasConfigFile()
->hasViews()
->hasTranslations()
->hasMigration('create_admin_kit_documents_table')
->hasMigrations([
'create_admin_kit_documents_table',
'add_link_column_to_admin_kit_documents_table',
])
->hasCommand(DocumentsCommand::class);
}

Expand Down
1 change: 1 addition & 0 deletions src/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Document extends AbstractModel implements HasMedia

protected $fillable = [
'title',
'link',
];

protected $translatable = [
Expand Down
14 changes: 8 additions & 6 deletions src/UI/API/Data/DocumentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class DocumentData extends Data
{
public function __construct(
public string $title,
public string $file,
public string $fileMime,
public int $fileSize,
public ?string $link,
public ?array $file,
public string $createdAt,
) {
}
Expand All @@ -25,9 +24,12 @@ public static function fromModel(Document $document): DocumentData

return new self(
title: $document->title,

Check failure on line 26 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::$title.

Check failure on line 26 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::$title.
file: $media->getUrl(),
fileMime: $media->mime_type,
fileSize: $media->size,
link: $document->link,

Check failure on line 27 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::$link.

Check failure on line 27 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::$link.
file: $media ? [
'url' => $media->getUrl(),
'mime' => $media->mime_type,
'size' => $media->size,
] : null,
createdAt: $document->created_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::$created_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::$created_at.
);
}
Expand Down
18 changes: 16 additions & 2 deletions src/UI/Filament/Resources/DocumentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use AdminKit\Documents\Models\Document;
use AdminKit\Documents\UI\Filament\Resources\DocumentResource\Pages;
use Filament\Forms;
use Filament\Forms\Components\Tabs\Tab;
use Filament\Resources\Resource;
use Filament\Tables;

Expand All @@ -19,8 +20,21 @@ public static function form(Forms\Form $form): Forms\Form
{
return $form
->schema([
Forms\Components\SpatieMediaLibraryFileUpload::make('file')
->label(__('admin-kit-documents::documents.resource.file')),
Forms\Components\Tabs::make('')
->tabs(fn () => [
Tab::make(__('admin-kit-documents::documents.resource.file'))
->schema([
Forms\Components\SpatieMediaLibraryFileUpload::make('file')
->label(''),
]),
Tab::make(__('admin-kit-documents::documents.resource.link'))
->schema([
Forms\Components\TextInput::make('link')
->label('')
->placeholder('https://youtube.com/'),
]),
])
->activeTab(fn (?Document $record) => $record?->link ? 2 : 1),

Check failure on line 37 in src/UI/Filament/Resources/DocumentResource.php

View workflow job for this annotation

GitHub Actions / phpstan

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

Check failure on line 37 in src/UI/Filament/Resources/DocumentResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property AdminKit\Documents\Models\Document::$link.
TranslatableTabs::make(fn ($locale) => Forms\Components\Tabs\Tab::make($locale)->schema([
Forms\Components\TextInput::make("title.$locale")
->label(__('admin-kit-documents::documents.resource.title'))
Expand Down

0 comments on commit 3a5537c

Please sign in to comment.