NewsCategoryResource.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. use Translatable;
  22. public static function form(Form $form): Form
  23. {
  24. return $form
  25. ->schema([
  26. //
  27. Section::make("")->schema([
  28. Translate::make()->schema(fn (string $locale) => [
  29. TextInput::make('name')->required($locale == 'zh_TW')->maxLength(40)->label("分類名稱")
  30. ])
  31. ->locales(["zh_TW", "en"])
  32. ->columnSpan(5),
  33. TextInput::make('order')->label("排序")->integer()->default(0)->columnSpan(1)
  34. ])->columns(4)
  35. ]);
  36. }
  37. public static function table(Table $table): Table
  38. {
  39. return $table
  40. ->columns([
  41. //
  42. TextColumn::make('name')->label("分類名稱"),
  43. TextColumn::make(name: 'created_at')->label("建立時間")->date(),
  44. TextColumn::make('updated_at')->label("更新時間")->date()
  45. ])
  46. ->filters([
  47. //
  48. ])
  49. ->actions([
  50. // Tables\Actions\ViewAction::make(),
  51. Tables\Actions\EditAction::make(),
  52. Tables\Actions\DeleteAction::make()
  53. ])
  54. ->bulkActions([
  55. Tables\Actions\BulkActionGroup::make([
  56. Tables\Actions\DeleteBulkAction::make(),
  57. ]),
  58. ])
  59. ->defaultSort('order', 'desc')
  60. ->defaultSort('created_at', 'desc');
  61. }
  62. public static function getRelations(): array
  63. {
  64. return [
  65. //
  66. ];
  67. }
  68. public static function getPages(): array
  69. {
  70. return [
  71. 'index' => Pages\ListNewsCategories::route('/'),
  72. 'create' => Pages\CreateNewsCategory::route('/create'),
  73. 'edit' => Pages\EditNewsCategory::route('/{record}/edit'),
  74. ];
  75. }
  76. }