AlbumCategoryResource.php 3.0KB

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