Skip to content

Commit

Permalink
feat: support filament v3
Browse files Browse the repository at this point in the history
  • Loading branch information
daurensky committed Feb 12, 2024
1 parent d085e38 commit e8a5b9f
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 59 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,21 @@ php artisan vendor:publish --tag="admin-kit-pages-views"
## Usage

```php
$pages = new AdminKit\Pages();
echo $pages->echoPhrase('Hello, AdminKit!');
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
...
->plugins([
...
\AdminKit\Pages\FilamentPlugin::make(),
]);
}
}
```

## Testing
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
],
"require": {
"php": "^8.1",
"filament/filament": "^2.0",
"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",
"filament/filament": "^3.0-stable",
"filament/spatie-laravel-translatable-plugin": "^3.0-stable",
"ibecsystems/admin-kit-core": "^3.1",
"ibecsystems/admin-kit-navigation": "^3.0",
"ibecsystems/admin-kit-seo": "^3.0",
"illuminate/contracts": "^10.0",
"spatie/laravel-package-tools": "^1.14.0",
"spatie/laravel-data": "^3.2",
"spatie/laravel-json-api-paginate": "^1.13",
"spatie/laravel-query-builder": "^5.2",
"spatie/laravel-query-builder": "^5.7",
"spatie/laravel-translatable": "^6.5"
},
"require-dev": {
Expand Down
31 changes: 31 additions & 0 deletions src/FilamentPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace AdminKit\Pages;

use Filament\Panel;
use Filament\Contracts\Plugin;
use AdminKit\Pages\UI\Filament\Resources\PageResource;

class FilamentPlugin implements Plugin
{
public function getId(): string
{
return 'filament-plugin-admin-kit-pages';
}

public function register(Panel $panel): void
{
$panel->resources([
PageResource::class,
]);
}

public function boot(Panel $panel): void
{
}

public static function make(): static
{
return app(static::class);
}
}
24 changes: 1 addition & 23 deletions src/PagesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

namespace AdminKit\Pages;

use Spatie\LaravelPackageTools\Package;
use AdminKit\Pages\Commands\PagesCommand;
use AdminKit\Pages\Models\Page;
use AdminKit\Pages\Providers\FilamentServiceProvider;
use AdminKit\Pages\Providers\RouteServiceProvider;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use RyanChandler\FilamentNavigation\Facades\FilamentNavigation;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class PagesServiceProvider extends PackageServiceProvider
Expand All @@ -31,23 +26,6 @@ public function configurePackage(Package $package): void

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()
->label('slug'),
]);
}
}
17 changes: 0 additions & 17 deletions src/Providers/FilamentServiceProvider.php

This file was deleted.

12 changes: 5 additions & 7 deletions src/UI/Filament/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use AdminKit\SEO\Forms\Components\SEOComponent;
use Filament\Forms;
use Filament\Forms\Components\Tabs;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
Expand All @@ -26,13 +24,13 @@ class PageResource extends Resource

protected static ?string $navigationGroup = 'Страницы';

protected static ?string $navigationIcon = 'heroicon-o-clipboard-list';
protected static ?string $navigationIcon = 'heroicon-o-document-duplicate';

public static function form(Form $form): Form
public static function form(Forms\Form $form): Forms\Form
{
return $form
->schema([
Forms\Components\Card::make([
Forms\Components\Section::make([
Forms\Components\TextInput::make('page_title')
->label('Название страницы')
->required()
Expand All @@ -45,7 +43,7 @@ function (string $context, $state, callable $set) {
}
),
Forms\Components\TextInput::make('slug')
->disabled()
->readOnly()
->required()
->unique(Page::class, 'slug', ignoreRecord: true),
])->columns(),
Expand All @@ -62,7 +60,7 @@ function (string $context, $state, callable $set) {
]);
}

public static function table(Table $table): Table
public static function table(Tables\Table $table): Tables\Table
{
return $table
->columns([
Expand Down
5 changes: 3 additions & 2 deletions src/UI/Filament/Resources/PageResource/Pages/EditPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
namespace AdminKit\Pages\UI\Filament\Resources\PageResource\Pages;

use AdminKit\Pages\UI\Filament\Resources\PageResource;
use Filament\Pages\Actions;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditPage extends EditRecord
{
protected static string $resource = PageResource::class;

protected function getActions(): array
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}
4 changes: 2 additions & 2 deletions src/UI/Filament/Resources/PageResource/Pages/ListPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace AdminKit\Pages\UI\Filament\Resources\PageResource\Pages;

use AdminKit\Pages\UI\Filament\Resources\PageResource;
use Filament\Pages\Actions;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListPage extends ListRecords
{
protected static string $resource = PageResource::class;

protected function getActions(): array
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
Expand Down

0 comments on commit e8a5b9f

Please sign in to comment.