feat: implement full-stack awards module with Filament management, database support, and localization.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Awards;
|
||||
|
||||
use App\Filament\Admin\Resources\Awards\Pages\CreateAward;
|
||||
use App\Filament\Admin\Resources\Awards\Pages\EditAward;
|
||||
use App\Filament\Admin\Resources\Awards\Pages\ListAwards;
|
||||
use App\Filament\Admin\Resources\Awards\Schemas\AwardForm;
|
||||
use App\Filament\Admin\Resources\Awards\Tables\AwardsTable;
|
||||
use App\Models\Award;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class AwardResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Award::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-trophy';
|
||||
|
||||
protected static ?int $navigationSort = 46;
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('awards.navigation_group');
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('awards.navigation_label');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('awards.model_label');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('awards.plural_model_label');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return AwardForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return AwardsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListAwards::route('/'),
|
||||
'create' => CreateAward::route('/create'),
|
||||
'edit' => EditAward::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Awards\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\Awards\AwardResource;
|
||||
use App\Filament\Admin\Resources\Components\TranslationTabs;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAward extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AwardResource::class;
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return __('awards.create') ?? 'Yeni Ödül Ekle';
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getCreatedNotificationTitle(): ?string
|
||||
{
|
||||
return __('awards.created_successfully') ?? 'Ödül başarıyla eklendi.';
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
TranslationTabs::saveTranslations($this->record, $this->form->getState());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Awards\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\Awards\AwardResource;
|
||||
use App\Filament\Admin\Resources\Components\TranslationTabs;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAward extends EditRecord
|
||||
{
|
||||
protected static string $resource = AwardResource::class;
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return __('awards.edit') ?? 'Ödülü Düzenle';
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make()
|
||||
->label(__('awards.delete') ?? 'Sil'),
|
||||
ForceDeleteAction::make()
|
||||
->label(__('awards.force_delete') ?? 'Kalıcı Olarak Sil'),
|
||||
RestoreAction::make()
|
||||
->label(__('awards.restore') ?? 'Geri Yükle'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getSavedNotificationTitle(): ?string
|
||||
{
|
||||
return __('awards.updated_successfully') ?? 'Ödül başarıyla güncellendi.';
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
return array_merge($data, TranslationTabs::fillFromRecord($this->record));
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
TranslationTabs::saveTranslations($this->record, $this->form->getState());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Awards\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\Awards\AwardResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAwards extends ListRecords
|
||||
{
|
||||
protected static string $resource = AwardResource::class;
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return __('awards.title') ?? 'Ödüllerimiz';
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label(__('awards.create') ?? 'Yeni Ödül Ekle'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Awards\Schemas;
|
||||
|
||||
use App\Filament\Admin\Resources\Components\TranslationTabs;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class AwardForm
|
||||
{
|
||||
public static function categoryOptions(): array
|
||||
{
|
||||
return [
|
||||
'hackathon' => __('awards.category_hackathon') ?? 'Hackathon',
|
||||
'export' => __('awards.category_export') ?? 'İhracat',
|
||||
'innovation' => __('awards.category_innovation') ?? 'İnovasyon',
|
||||
'design' => __('awards.category_design') ?? 'Tasarım',
|
||||
'general' => __('awards.category_general') ?? 'Genel',
|
||||
];
|
||||
}
|
||||
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(3)
|
||||
->schema([
|
||||
Section::make(__('awards.content_section') ?? 'Ödül İçeriği')
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label(__('awards.title_field') ?? 'Ödül Başlığı (Varsayılan)')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('issuer')
|
||||
->label(__('awards.issuer_field') ?? 'Ödülü Veren Kurum (Varsayılan)')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
Textarea::make('description')
|
||||
->label(__('awards.description_field') ?? 'Açıklama (Varsayılan)')
|
||||
->required()
|
||||
->rows(5)
|
||||
->columnSpanFull(),
|
||||
|
||||
TranslationTabs::make([
|
||||
'title' => [
|
||||
'type' => 'text',
|
||||
'label' => __('awards.title_field') ?? 'Ödül Başlığı',
|
||||
'required' => false,
|
||||
'maxLength' => 255,
|
||||
],
|
||||
'issuer' => [
|
||||
'type' => 'text',
|
||||
'label' => __('awards.issuer_field') ?? 'Ödülü Veren Kurum',
|
||||
'required' => false,
|
||||
'maxLength' => 255,
|
||||
],
|
||||
'description' => [
|
||||
'type' => 'textarea',
|
||||
'label' => __('awards.description_field') ?? 'Açıklama',
|
||||
'required' => false,
|
||||
'rows' => 5,
|
||||
],
|
||||
]),
|
||||
])
|
||||
->columnSpan(2),
|
||||
|
||||
Section::make(__('awards.settings_section') ?? 'Ödül Ayarları')
|
||||
->schema([
|
||||
FileUpload::make('image')
|
||||
->label(__('awards.image_field') ?? 'Ödül Görseli / Logo')
|
||||
->image()
|
||||
->disk('public')
|
||||
->directory('awards')
|
||||
->required(),
|
||||
|
||||
DatePicker::make('award_date')
|
||||
->label(__('awards.date_field') ?? 'Ödül Tarihi')
|
||||
->required(),
|
||||
|
||||
Select::make('category')
|
||||
->label(__('awards.category_field') ?? 'Kategori')
|
||||
->options(self::categoryOptions())
|
||||
->default('general')
|
||||
->required()
|
||||
->native(false),
|
||||
|
||||
TextInput::make('external_link')
|
||||
->label(__('awards.link_field') ?? 'Doğrulama / Haber Linki')
|
||||
->url()
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('sort_order')
|
||||
->label(__('awards.sort_order_field') ?? 'Sıralama')
|
||||
->numeric()
|
||||
->default(0)
|
||||
->minValue(0),
|
||||
|
||||
Toggle::make('is_featured')
|
||||
->label(__('awards.is_featured_field') ?? 'Öne Çıkarılan Ödül')
|
||||
->default(false),
|
||||
|
||||
Toggle::make('is_active')
|
||||
->label(__('awards.is_active_field') ?? 'Aktif / Görünür')
|
||||
->default(true),
|
||||
])
|
||||
->columnSpan(1),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\Awards\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AwardsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
ImageColumn::make('image')
|
||||
->label(__('awards.table_image') ?? 'Logo')
|
||||
->disk('public')
|
||||
->square()
|
||||
->size(50),
|
||||
|
||||
TextColumn::make('title')
|
||||
->label(__('awards.table_title') ?? 'Ödül Başlığı')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->limit(40),
|
||||
|
||||
TextColumn::make('issuer')
|
||||
->label(__('awards.table_issuer') ?? 'Veren Kurum')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->limit(30),
|
||||
|
||||
TextColumn::make('award_date')
|
||||
->label(__('awards.table_date') ?? 'Ödül Tarihi')
|
||||
->date('d.m.Y')
|
||||
->sortable()
|
||||
->alignCenter(),
|
||||
|
||||
TextColumn::make('category')
|
||||
->label(__('awards.table_category') ?? 'Kategori')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state): string => match ($state) {
|
||||
'hackathon' => __('awards.category_hackathon') ?? 'Hackathon',
|
||||
'export' => __('awards.category_export') ?? 'İhracat',
|
||||
'innovation' => __('awards.category_innovation') ?? 'İnovasyon',
|
||||
'design' => __('awards.category_design') ?? 'Tasarım',
|
||||
default => __('awards.category_general') ?? 'Genel',
|
||||
})
|
||||
->sortable()
|
||||
->alignCenter(),
|
||||
|
||||
ToggleColumn::make('is_featured')
|
||||
->label(__('awards.table_is_featured') ?? 'Öne Çıkan')
|
||||
->alignCenter(),
|
||||
|
||||
ToggleColumn::make('is_active')
|
||||
->label(__('awards.table_is_active') ?? 'Aktif')
|
||||
->alignCenter(),
|
||||
|
||||
TextColumn::make('sort_order')
|
||||
->label(__('awards.sort_order_field') ?? 'Sıra')
|
||||
->sortable()
|
||||
->alignCenter(),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('is_active')
|
||||
->label(__('awards.is_active_field') ?? 'Aktiflik Durumu'),
|
||||
TernaryFilter::make('is_featured')
|
||||
->label(__('awards.is_featured_field') ?? 'Öne Çıkarılma Durumu'),
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->label(__('awards.edit') ?? 'Düzenle'),
|
||||
])
|
||||
->actions([
|
||||
// Individual actions can be put here if necessary
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make()
|
||||
->label(__('awards.delete') ?? 'Sil'),
|
||||
RestoreBulkAction::make()
|
||||
->label(__('awards.restore') ?? 'Geri Yükle'),
|
||||
ForceDeleteBulkAction::make()
|
||||
->label(__('awards.force_delete') ?? 'Kalıcı Olarak Sil'),
|
||||
]),
|
||||
])
|
||||
->defaultSort('sort_order', 'asc')
|
||||
->reorderable('sort_order');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\HasTranslations;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Award extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasTranslations;
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'description',
|
||||
'issuer',
|
||||
'award_date',
|
||||
'image',
|
||||
'external_link',
|
||||
'is_featured',
|
||||
'is_active',
|
||||
'sort_order',
|
||||
'category',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $translatable = [
|
||||
'title',
|
||||
'description',
|
||||
'issuer',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'award_date' => 'date',
|
||||
'is_featured' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
public function scopeFeatured($query)
|
||||
{
|
||||
return $query->where('is_featured', true);
|
||||
}
|
||||
|
||||
public function scopeOrdered($query)
|
||||
{
|
||||
return $query
|
||||
->orderBy('sort_order', 'asc')
|
||||
->orderBy('award_date', 'desc');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user