Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: filament resource #7

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}