NewsCategoryResource.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Filament\Resources;
  3. use App\Filament\Resources\NewsCategoryResource\Pages;
  4. use App\Models\NewsCategory;
  5. use Filament\Forms\Components\Section;
  6. use Filament\Forms\Components\TextInput;
  7. use Filament\Forms\Form;
  8. use Filament\Resources\Concerns\Translatable;
  9. use Filament\Resources\Resource;
  10. use Filament\Tables;
  11. use Filament\Tables\Columns\TextColumn;
  12. use Filament\Tables\Table;
  13. use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
  14. class NewsCategoryResource extends Resource
  15. {
  16. protected static ?string $model = NewsCategory::class;
  17. protected static ?string $modelLabel = "文章分類管理";
  18. protected static ?string $navigationIcon = 'heroicon-o-rectangle-group';
  19. protected static ?string $navigationGroup = '上稿內容管理';
  20. protected static ?string $navigationLabel = "文章分類管理";
  21. protected static bool $shouldRegisterNavigation = false;
  22. use Translatable;
  23. public static function form(Form $form): Form
  24. {
  25. return $form
  26. ->schema([
  27. //
  28. Section::make("")->schema([
  29. Translate::make()->schema(fn (string $locale) => [
  30. TextInput::make('name')->required($locale == 'zh_TW')->maxLength(40)->label("分類名稱")
  31. ])
  32. ->locales(["zh_TW", "en"])
  33. ->columnSpan(5),
  34. TextInput::make('order')->label("排序")->integer()->default(0)->columnSpan(1)
  35. ])->columns(4)
  36. ]);
  37. }
  38. public static function table(Table $table): Table
  39. {
  40. return $table
  41. ->columns([
  42. //
  43. TextColumn::make('name')->label("分類名稱"),
  44. TextColumn::make(name: 'created_at')->label("建立時間")->date(),
  45. TextColumn::make('updated_at')->label("更新時間")->date()
  46. ])
  47. ->filters([
  48. //
  49. ])
  50. ->actions([
  51. // Tables\Actions\ViewAction::make(),
  52. Tables\Actions\EditAction::make(),
  53. Tables\Actions\DeleteAction::make()
  54. ])
  55. ->bulkActions([
  56. Tables\Actions\BulkActionGroup::make([
  57. Tables\Actions\DeleteBulkAction::make(),
  58. ]),
  59. ])
  60. ->defaultSort('order', 'desc')
  61. ->defaultSort('created_at', 'desc');
  62. }
  63. public static function getRelations(): array
  64. {
  65. return [
  66. //
  67. ];
  68. }
  69. public static function getPages(): array
  70. {
  71. return [
  72. 'index' => Pages\ListNewsCategories::route('/'),
  73. 'create' => Pages\CreateNewsCategory::route('/create'),
  74. 'edit' => Pages\EditNewsCategory::route('/{record}/edit'),
  75. ];
  76. }
  77. }