Skip to content

Commit

Permalink
Merge pull request #7 from IBEC-BOX/refactor/filament-resource
Browse files Browse the repository at this point in the history
refactor: filament resource
  • Loading branch information
daurensky authored Apr 8, 2024
2 parents 67854b0 + bdc57c2 commit 0f1de76
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 42 deletions.
3 changes: 3 additions & 0 deletions resources/lang/en/vacancy.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
'image' => 'Image',
'action_button' => 'Action button',
'link' => 'Link',
'gallery' => 'Gallery',

'created_at' => 'Created At',
'updated_at' => 'Updated At',
],

'empty' => 'Empty.',
];
3 changes: 3 additions & 0 deletions resources/lang/ru/vacancy.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
'image' => 'Изображение',
'action_button' => 'Кнопка действия',
'link' => 'Ссылка',
'gallery' => 'Галерея',

'created_at' => 'Создан',
'updated_at' => 'Обновлен',
],

'empty' => 'Пусто.',
];
11 changes: 5 additions & 6 deletions src/UI/Filament/Resources/VacancyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public static function form(Forms\Form $form): Forms\Form
TranslatableTabs::make(fn ($locale) => Forms\Components\Tabs\Tab::make($locale)->schema([
Forms\Components\TextInput::make('title.'.$locale)
->label(__('admin-kit-vacancy::vacancy.resource.title'))
->required(),
->required($locale === app()->getLocale()),
Forms\Components\TextInput::make('subtitle.'.$locale)
->label(__('admin-kit-vacancy::vacancy.resource.subtitle'))
->required(),
->required($locale === app()->getLocale()),
Forms\Components\Section::make(__('admin-kit-vacancy::vacancy.resource.action_button'))->schema([
Forms\Components\TextInput::make('action_title.'.$locale)
->label(__('admin-kit-vacancy::vacancy.resource.title')),
Expand Down Expand Up @@ -82,8 +82,7 @@ public static function getRelations(): array
public static function getPages(): array
{
return [
'index' => Pages\ListVacancy::route('/'),
'create' => Pages\CreateVacancy::route('/create'),
'index' => Pages\CreateVacancy::route('/'),
'edit' => Pages\EditVacancy::route('/{record}/edit'),
];
}
Expand All @@ -104,7 +103,7 @@ public static function getNavigationUrl(): string
->first();

return $vacancy
? route('filament.admin-kit.resources.vacancies.edit', $vacancy)
: route('filament.admin-kit.resources.vacancies.create');
? self::getUrl('edit', ['record' => $vacancy])
: self::getUrl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,5 @@ class CreateVacancy extends CreateRecord
{
protected static string $resource = VacancyResource::class;

protected function getActions(): array
{
return [
//
];
}

protected function getRedirectUrl(): string
{
return VacancyResource::getUrl();
}
protected static bool $canCreateAnother = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class EditVacancy extends EditRecord
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\DeleteAction::make()
->successRedirectUrl(VacancyResource::getUrl()),
];
}
}
19 changes: 0 additions & 19 deletions src/UI/Filament/Resources/VacancyResource/Pages/ListVacancy.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class VacancyGalleryRelationManager extends RelationManager
{
Expand All @@ -27,7 +28,7 @@ public function form(Form $form): Form
TranslatableTabs::make(fn ($locale) => Tab::make($locale)->schema([
Forms\Components\TextInput::make('title.'.$locale)
->label(__('admin-kit-vacancy::vacancy.resource.title'))
->required(),
->required($locale === app()->getLocale()),
]))->columnSpan(2),
]);
}
Expand All @@ -43,9 +44,6 @@ public function table(Table $table): Table
Tables\Columns\TextColumn::make('title')
->label(__('admin-kit-vacancy::vacancy.resource.title')),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
Expand All @@ -57,6 +55,23 @@ public function table(Table $table): Table
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
])
->emptyStateHeading(__('admin-kit-vacancy::vacancy.empty'))
->emptyStateDescription('');
}

public static function getTitle(Model $ownerRecord, string $pageClass): string
{
return __('admin-kit-vacancy::vacancy.resource.gallery');
}

public static function getModelLabel(): string
{
return __('admin-kit-vacancy::vacancy.resource.gallery');
}

protected static function getPluralModelLabel(): string
{
return __('admin-kit-vacancy::vacancy.resource.gallery');
}
}

0 comments on commit 0f1de76

Please sign in to comment.