From 51a12509305f2b1b75bbae7462eef70ad47a2908 Mon Sep 17 00:00:00 2001 From: Bakytzhan Azimbay Date: Mon, 10 Jul 2023 03:07:28 +0600 Subject: [PATCH 1/7] navigation add to page --- composer.json | 1 + .../create_admin_kit_pages_table.php.stub | 13 +++-- resources/lang/en/page-navigation.php | 11 ++++ resources/lang/ru/page-navigation.php | 11 ++++ src/Models/Page.php | 18 ++++-- src/PagesServiceProvider.php | 20 +++++++ src/UI/Filament/Resources/PageResource.php | 58 +++++++++++++++---- 7 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 resources/lang/en/page-navigation.php create mode 100644 resources/lang/ru/page-navigation.php diff --git a/composer.json b/composer.json index 7bb5ae5..f13cc4f 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "filament/filament": "^2.0", "filament/spatie-laravel-translatable-plugin": "^2.0", "ibecsystems/admin-kit-core": "^2.0", + "ibecsystems/admin-kit-navigation": "^2.0", "illuminate/contracts": "^10.0", "spatie/laravel-package-tools": "^1.14.0", "spatie/laravel-data": "^3.2", diff --git a/database/migrations/create_admin_kit_pages_table.php.stub b/database/migrations/create_admin_kit_pages_table.php.stub index 2fdfdd6..1c79bad 100644 --- a/database/migrations/create_admin_kit_pages_table.php.stub +++ b/database/migrations/create_admin_kit_pages_table.php.stub @@ -10,10 +10,15 @@ return new class extends Migration { Schema::create('admin_kit_pages', function (Blueprint $table) { $table->id(); - - // add fields - $table->jsonb('title')->default('{}'); - + $table->json('title'); + $table->json('content'); + $table->json('page_title')->nullable(); + $table->json('seo_title')->nullable(); + $table->json('seo_description')->nullable(); + $table->string('slug'); + $table->boolean('site_display')->default(1); + $table->boolean('site_map_index')->default(1); + $table->softDeletes(); $table->timestamps(); }); } diff --git a/resources/lang/en/page-navigation.php b/resources/lang/en/page-navigation.php new file mode 100644 index 0000000..3cc4679 --- /dev/null +++ b/resources/lang/en/page-navigation.php @@ -0,0 +1,11 @@ + [ + 'page' => 'Page', + 'page_id' => 'Page', + 'created_at' => 'Created at', + 'updated_at' => 'Updated at', + + ], +]; diff --git a/resources/lang/ru/page-navigation.php b/resources/lang/ru/page-navigation.php new file mode 100644 index 0000000..d5a0c2c --- /dev/null +++ b/resources/lang/ru/page-navigation.php @@ -0,0 +1,11 @@ + [ + 'page' => 'Страница', + 'page_id' => 'Страница', + 'created_at' => 'Создано', + 'updated_at' => 'Изменено', + + ], +]; diff --git a/src/Models/Page.php b/src/Models/Page.php index 25cfe33..737648d 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -16,14 +16,24 @@ class Page extends AbstractModel protected $fillable = [ 'title', + 'content', + 'seo_title', + 'seo_description', + 'slug', + 'position', + 'site_display', + 'site_map_index', ]; - protected $casts = [ - // + public array $translatable = [ + 'title', + 'content', + 'seo_title', + 'seo_description' ]; - protected $translatable = [ - 'title', + protected $casts = [ + // ]; protected static function newFactory(): PageFactory diff --git a/src/PagesServiceProvider.php b/src/PagesServiceProvider.php index 077a27c..e53057c 100644 --- a/src/PagesServiceProvider.php +++ b/src/PagesServiceProvider.php @@ -5,6 +5,10 @@ use AdminKit\Pages\Commands\PagesCommand; use AdminKit\Pages\Providers\FilamentServiceProvider; use AdminKit\Pages\Providers\RouteServiceProvider; +use AdminKit\Pages\Models\Page; +use Filament\Forms\Components\Select; +use Filament\Forms\Components\TextInput; +use RyanChandler\FilamentNavigation\Facades\FilamentNavigation; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -30,4 +34,20 @@ public function registeringPackage() $this->app->register(FilamentServiceProvider::class); $this->app->register(RouteServiceProvider::class); } + + public function packageBooted() + { + FilamentNavigation::addItemType(__('filament-navigation.attributes.page'), [ + Select::make('page_id') + ->label(__('filament-navigation.attributes.page_id')) + ->searchable() + ->options(function () { + return Page::pluck('title', 'id'); + }), + + TextInput::make('slug') + ->required() + ->unique(Page::class, 'slug', ignoreRecord: true), + ]); + } } diff --git a/src/UI/Filament/Resources/PageResource.php b/src/UI/Filament/Resources/PageResource.php index dd26704..7df8b1d 100644 --- a/src/UI/Filament/Resources/PageResource.php +++ b/src/UI/Filament/Resources/PageResource.php @@ -10,34 +10,62 @@ use Filament\Resources\Resource; use Filament\Resources\Table; use Filament\Tables; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\SoftDeletingScope; +use Illuminate\Support\Str; class PageResource extends Resource { use Translatable; protected static ?string $model = Page::class; - - protected static ?string $navigationIcon = 'heroicon-o-x'; + protected static ?string $modelLabel = 'Страницу'; + protected static ?string $pluralModelLabel = 'Страницы'; + protected static ?string $navigationGroup = 'Страницы'; + protected static ?string $navigationIcon = 'heroicon-o-clipboard-list'; public static function form(Form $form): Form { return $form ->schema([ - Forms\Components\TextInput::make('title')->required(), - ]) - ->columns(1); + Forms\Components\TextInput::make('page_title') + ->label('Название страницы') + ->required(), + Forms\Components\Card::make([ + Forms\Components\TextInput::make('title') + ->label('Название') + ->required() + ->lazy() + ->afterStateUpdated( + function (string $context, $state, callable $set) { + if ($context === 'create') { + $set('slug', Str::slug($state)); + } + } + ), + + Forms\Components\TextInput::make('slug') + ->disabled() + ->required() + ->unique(Page::class, 'slug', ignoreRecord: true), + + Forms\Components\RichEditor::make('content')->label('Контент')->required()->columnSpan(2), + ])->columns(), + Forms\Components\TextInput::make('seo_title'), + Forms\Components\TextInput::make('seo_description'), + Forms\Components\Checkbox::make('site_display'), + Forms\Components\Checkbox::make('site_map_index'), + ]); } public static function table(Table $table): Table { return $table ->columns([ - Tables\Columns\TextColumn::make('id')->sortable(), - Tables\Columns\TextColumn::make('title'), + Tables\Columns\TextColumn::make('title')->label('Название')->searchable(), ]) - ->defaultSort('id', 'desc') ->filters([ - // + Tables\Filters\TrashedFilter::make(), ]) ->actions([ Tables\Actions\EditAction::make(), @@ -45,6 +73,8 @@ public static function table(Table $table): Table ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\ForceDeleteBulkAction::make(), + Tables\Actions\RestoreBulkAction::make(), ]); } @@ -58,12 +88,20 @@ public static function getRelations(): array public static function getPages(): array { return [ - 'index' => Pages\ListPage::route('/'), + 'index' => Pages\ListPages::route('/'), 'create' => Pages\CreatePage::route('/create'), 'edit' => Pages\EditPage::route('/{record}/edit'), ]; } + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } + public static function getTranslatableLocales(): array { return config('admin-kit.locales'); From b32450964717c775c883e7798252ec7095134825 Mon Sep 17 00:00:00 2001 From: Bahataha Date: Sun, 9 Jul 2023 21:08:00 +0000 Subject: [PATCH 2/7] Fix styling --- src/Models/Page.php | 2 +- src/PagesServiceProvider.php | 2 +- src/UI/Filament/Resources/PageResource.php | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Models/Page.php b/src/Models/Page.php index 737648d..b43ec7e 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -29,7 +29,7 @@ class Page extends AbstractModel 'title', 'content', 'seo_title', - 'seo_description' + 'seo_description', ]; protected $casts = [ diff --git a/src/PagesServiceProvider.php b/src/PagesServiceProvider.php index e53057c..a96df7f 100644 --- a/src/PagesServiceProvider.php +++ b/src/PagesServiceProvider.php @@ -3,9 +3,9 @@ namespace AdminKit\Pages; use AdminKit\Pages\Commands\PagesCommand; +use AdminKit\Pages\Models\Page; use AdminKit\Pages\Providers\FilamentServiceProvider; use AdminKit\Pages\Providers\RouteServiceProvider; -use AdminKit\Pages\Models\Page; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use RyanChandler\FilamentNavigation\Facades\FilamentNavigation; diff --git a/src/UI/Filament/Resources/PageResource.php b/src/UI/Filament/Resources/PageResource.php index 7df8b1d..ca47c40 100644 --- a/src/UI/Filament/Resources/PageResource.php +++ b/src/UI/Filament/Resources/PageResource.php @@ -19,9 +19,13 @@ class PageResource extends Resource use Translatable; protected static ?string $model = Page::class; + protected static ?string $modelLabel = 'Страницу'; + protected static ?string $pluralModelLabel = 'Страницы'; + protected static ?string $navigationGroup = 'Страницы'; + protected static ?string $navigationIcon = 'heroicon-o-clipboard-list'; public static function form(Form $form): Form From 302ec5bd25b32eafc619cf8128ec88a48669a5ea Mon Sep 17 00:00:00 2001 From: Bakytzhan Azimbay Date: Mon, 10 Jul 2023 06:22:13 +0600 Subject: [PATCH 3/7] navigation --- src/UI/Filament/Resources/PageResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UI/Filament/Resources/PageResource.php b/src/UI/Filament/Resources/PageResource.php index 7df8b1d..c3a8489 100644 --- a/src/UI/Filament/Resources/PageResource.php +++ b/src/UI/Filament/Resources/PageResource.php @@ -88,7 +88,7 @@ public static function getRelations(): array public static function getPages(): array { return [ - 'index' => Pages\ListPages::route('/'), + 'index' => Pages\ListPage::route('/'), 'create' => Pages\CreatePage::route('/create'), 'edit' => Pages\EditPage::route('/{record}/edit'), ]; From 450951e11ce6ff6eff434e1ffce4a23f72cc5739 Mon Sep 17 00:00:00 2001 From: Bakytzhan Azimbay Date: Fri, 14 Jul 2023 17:25:49 +0600 Subject: [PATCH 4/7] seo --- composer.json | 1 + .../create_admin_kit_pages_table.php.stub | 8 ++---- src/Models/Page.php | 8 +++--- src/UI/Filament/Resources/PageResource.php | 28 +++++++++---------- .../PageResource/Pages/CreatePage.php | 9 ------ .../Resources/PageResource/Pages/EditPage.php | 3 -- .../Resources/PageResource/Pages/ListPage.php | 3 -- 7 files changed, 22 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index f13cc4f..ee543a5 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "filament/spatie-laravel-translatable-plugin": "^2.0", "ibecsystems/admin-kit-core": "^2.0", "ibecsystems/admin-kit-navigation": "^2.0", + "ibecsystems/admin-kit-seo": "^2.0", "illuminate/contracts": "^10.0", "spatie/laravel-package-tools": "^1.14.0", "spatie/laravel-data": "^3.2", diff --git a/database/migrations/create_admin_kit_pages_table.php.stub b/database/migrations/create_admin_kit_pages_table.php.stub index 1c79bad..ea15ae0 100644 --- a/database/migrations/create_admin_kit_pages_table.php.stub +++ b/database/migrations/create_admin_kit_pages_table.php.stub @@ -10,11 +10,9 @@ return new class extends Migration { Schema::create('admin_kit_pages', function (Blueprint $table) { $table->id(); - $table->json('title'); - $table->json('content'); - $table->json('page_title')->nullable(); - $table->json('seo_title')->nullable(); - $table->json('seo_description')->nullable(); + $table->jsonb('title'); + $table->jsonb('content'); + $table->jsonb('page_title')->nullable(); $table->string('slug'); $table->boolean('site_display')->default(1); $table->boolean('site_map_index')->default(1); diff --git a/src/Models/Page.php b/src/Models/Page.php index b43ec7e..e9c672a 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -5,20 +5,22 @@ use AdminKit\Core\Abstracts\Models\AbstractModel; use AdminKit\Pages\Database\Factories\PageFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Translatable\HasTranslations; +use AdminKit\SEO\Traits\HasSEO; class Page extends AbstractModel { use HasFactory; use HasTranslations; + use HasSEO; + use SoftDeletes; protected $table = 'admin_kit_pages'; protected $fillable = [ 'title', 'content', - 'seo_title', - 'seo_description', 'slug', 'position', 'site_display', @@ -28,8 +30,6 @@ class Page extends AbstractModel public array $translatable = [ 'title', 'content', - 'seo_title', - 'seo_description', ]; protected $casts = [ diff --git a/src/UI/Filament/Resources/PageResource.php b/src/UI/Filament/Resources/PageResource.php index 8363227..14263f7 100644 --- a/src/UI/Filament/Resources/PageResource.php +++ b/src/UI/Filament/Resources/PageResource.php @@ -4,8 +4,9 @@ use AdminKit\Pages\Models\Page; use AdminKit\Pages\UI\Filament\Resources\PageResource\Pages; +use AdminKit\Core\Forms\Components\TranslatableTabs; use Filament\Forms; -use Filament\Resources\Concerns\Translatable; +use Filament\Forms\Components\Tabs; use Filament\Resources\Form; use Filament\Resources\Resource; use Filament\Resources\Table; @@ -13,11 +14,10 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Support\Str; +use AdminKit\SEO\Forms\Components\SEOComponent; class PageResource extends Resource { - use Translatable; - protected static ?string $model = Page::class; protected static ?string $modelLabel = 'Страницу'; @@ -32,12 +32,9 @@ public static function form(Form $form): Form { return $form ->schema([ - Forms\Components\TextInput::make('page_title') - ->label('Название страницы') - ->required(), Forms\Components\Card::make([ - Forms\Components\TextInput::make('title') - ->label('Название') + Forms\Components\TextInput::make('page_title') + ->label('Название страницы') ->required() ->lazy() ->afterStateUpdated( @@ -47,18 +44,21 @@ function (string $context, $state, callable $set) { } } ), - Forms\Components\TextInput::make('slug') ->disabled() ->required() ->unique(Page::class, 'slug', ignoreRecord: true), + ])->columns(), + + TranslatableTabs::make(fn ($locale) => Tabs\Tab::make($locale)->schema([ + Forms\Components\TextInput::make('title') + ->label('Название') + ->required(), Forms\Components\RichEditor::make('content')->label('Контент')->required()->columnSpan(2), - ])->columns(), - Forms\Components\TextInput::make('seo_title'), - Forms\Components\TextInput::make('seo_description'), - Forms\Components\Checkbox::make('site_display'), - Forms\Components\Checkbox::make('site_map_index'), + ]))->columnSpan(2), + + SEOComponent::make(), ]); } diff --git a/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php b/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php index 70153bd..1cecd4f 100644 --- a/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php +++ b/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php @@ -8,14 +8,5 @@ class CreatePage extends CreateRecord { - use CreateRecord\Concerns\Translatable; - protected static string $resource = PageResource::class; - - protected function getActions(): array - { - return [ - Actions\LocaleSwitcher::make(), - ]; - } } diff --git a/src/UI/Filament/Resources/PageResource/Pages/EditPage.php b/src/UI/Filament/Resources/PageResource/Pages/EditPage.php index f1a5219..03409da 100644 --- a/src/UI/Filament/Resources/PageResource/Pages/EditPage.php +++ b/src/UI/Filament/Resources/PageResource/Pages/EditPage.php @@ -8,14 +8,11 @@ class EditPage extends EditRecord { - use EditRecord\Concerns\Translatable; - protected static string $resource = PageResource::class; protected function getActions(): array { return [ - Actions\LocaleSwitcher::make(), Actions\DeleteAction::make(), ]; } diff --git a/src/UI/Filament/Resources/PageResource/Pages/ListPage.php b/src/UI/Filament/Resources/PageResource/Pages/ListPage.php index 5648814..7fe684c 100644 --- a/src/UI/Filament/Resources/PageResource/Pages/ListPage.php +++ b/src/UI/Filament/Resources/PageResource/Pages/ListPage.php @@ -8,14 +8,11 @@ class ListPage extends ListRecords { - use ListRecords\Concerns\Translatable; - protected static string $resource = PageResource::class; protected function getActions(): array { return [ - Actions\LocaleSwitcher::make(), Actions\CreateAction::make(), ]; } From 898d6d6055bf571f4ca145d20936b2b444c833b8 Mon Sep 17 00:00:00 2001 From: Bahataha Date: Fri, 14 Jul 2023 11:26:17 +0000 Subject: [PATCH 5/7] Fix styling --- src/Models/Page.php | 2 +- src/UI/Filament/Resources/PageResource.php | 4 ++-- src/UI/Filament/Resources/PageResource/Pages/CreatePage.php | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Models/Page.php b/src/Models/Page.php index e9c672a..6516e23 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -4,10 +4,10 @@ use AdminKit\Core\Abstracts\Models\AbstractModel; use AdminKit\Pages\Database\Factories\PageFactory; +use AdminKit\SEO\Traits\HasSEO; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Translatable\HasTranslations; -use AdminKit\SEO\Traits\HasSEO; class Page extends AbstractModel { diff --git a/src/UI/Filament/Resources/PageResource.php b/src/UI/Filament/Resources/PageResource.php index 14263f7..f95d450 100644 --- a/src/UI/Filament/Resources/PageResource.php +++ b/src/UI/Filament/Resources/PageResource.php @@ -2,9 +2,10 @@ namespace AdminKit\Pages\UI\Filament\Resources; +use AdminKit\Core\Forms\Components\TranslatableTabs; use AdminKit\Pages\Models\Page; use AdminKit\Pages\UI\Filament\Resources\PageResource\Pages; -use AdminKit\Core\Forms\Components\TranslatableTabs; +use AdminKit\SEO\Forms\Components\SEOComponent; use Filament\Forms; use Filament\Forms\Components\Tabs; use Filament\Resources\Form; @@ -14,7 +15,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Support\Str; -use AdminKit\SEO\Forms\Components\SEOComponent; class PageResource extends Resource { diff --git a/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php b/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php index 1cecd4f..37517f2 100644 --- a/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php +++ b/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php @@ -3,7 +3,6 @@ namespace AdminKit\Pages\UI\Filament\Resources\PageResource\Pages; use AdminKit\Pages\UI\Filament\Resources\PageResource; -use Filament\Pages\Actions; use Filament\Resources\Pages\CreateRecord; class CreatePage extends CreateRecord From 4753e0366f49ae48ec1b868123404f1f198dd1cd Mon Sep 17 00:00:00 2001 From: Bakytzhan Azimbay Date: Fri, 14 Jul 2023 18:35:47 +0600 Subject: [PATCH 6/7] test --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ba5769..46665c9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. -## Installation // 1 +## Installation You can install the package via composer: From 77a316a9258c54785d6be0655fd543aeb305f3fc Mon Sep 17 00:00:00 2001 From: Bakytzhan Azimbay Date: Wed, 19 Jul 2023 18:36:22 +0600 Subject: [PATCH 7/7] remove seo and translations --- database/migrations/create_admin_kit_pages_table.php.stub | 1 - src/Models/Page.php | 1 - src/UI/Filament/Resources/PageResource.php | 5 ----- 3 files changed, 7 deletions(-) diff --git a/database/migrations/create_admin_kit_pages_table.php.stub b/database/migrations/create_admin_kit_pages_table.php.stub index ea15ae0..d28dfcb 100644 --- a/database/migrations/create_admin_kit_pages_table.php.stub +++ b/database/migrations/create_admin_kit_pages_table.php.stub @@ -15,7 +15,6 @@ return new class extends Migration $table->jsonb('page_title')->nullable(); $table->string('slug'); $table->boolean('site_display')->default(1); - $table->boolean('site_map_index')->default(1); $table->softDeletes(); $table->timestamps(); }); diff --git a/src/Models/Page.php b/src/Models/Page.php index 6516e23..8c2f4d4 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -24,7 +24,6 @@ class Page extends AbstractModel 'slug', 'position', 'site_display', - 'site_map_index', ]; public array $translatable = [ diff --git a/src/UI/Filament/Resources/PageResource.php b/src/UI/Filament/Resources/PageResource.php index f95d450..1cc7b71 100644 --- a/src/UI/Filament/Resources/PageResource.php +++ b/src/UI/Filament/Resources/PageResource.php @@ -105,9 +105,4 @@ public static function getEloquentQuery(): Builder SoftDeletingScope::class, ]); } - - public static function getTranslatableLocales(): array - { - return config('admin-kit.locales'); - } }