NewsCategoryResource.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Filament\Resources;
  3. use App\Filament\Resources\NewsCategoryResource\Pages;
  4. use App\Filament\Resources\NewsCategoryResource\RelationManagers;
  5. use App\Models\NewsCategory;
  6. use Filament\Forms;
  7. use Filament\Forms\Components\Group;
  8. use Filament\Forms\Components\Radio;
  9. use Filament\Forms\Components\Section;
  10. use Filament\Forms\Components\TextInput;
  11. use Filament\Forms\Form;
  12. use Filament\Resources\Resource;
  13. use Filament\Tables;
  14. use Filament\Tables\Columns\TextColumn;
  15. use Filament\Tables\Table;
  16. use Illuminate\Database\Eloquent\Builder;
  17. use Illuminate\Database\Eloquent\SoftDeletingScope;
  18. class NewsCategoryResource extends Resource
  19. {
  20. protected static ?string $model = NewsCategory::class;
  21. protected static ?string $navigationIcon = 'heroicon-o-newspaper';
  22. protected static ?string $navigationLabel = "最新消息分類管理";
  23. protected static ?string $navigationGroup = '最新消息';
  24. protected static ?string $modelLabel = "最新消息分類管理";
  25. protected static ?int $navigationSort = 3;
  26. public static function form(Form $form): Form
  27. {
  28. return $form
  29. ->schema([
  30. Section::make("")->schema([
  31. Group::make()->schema([
  32. TextInput::make("name")->label("標題")->translatableTabs()->columnSpanFull(),
  33. Radio::make("visible")->label("顯示/不顯示")->options([1 => "顯示", 0 => "不顯示"])->inline()->default(1)
  34. ->columnSpan(2)
  35. ])->columns(4)->columnSpanFull()
  36. ])
  37. ]);
  38. }
  39. public static function table(Table $table): Table
  40. {
  41. return $table
  42. ->columns([
  43. TextColumn::make("name")->label("分類名稱"),
  44. TextColumn::make("visible_str")->label("顯示/不顯示")
  45. ])
  46. ->filters([
  47. //
  48. ])
  49. ->actions([
  50. Tables\Actions\EditAction::make(),
  51. ])
  52. ->bulkActions([
  53. Tables\Actions\BulkActionGroup::make([
  54. Tables\Actions\DeleteBulkAction::make(),
  55. ]),
  56. ]);
  57. }
  58. public static function getRelations(): array
  59. {
  60. return [
  61. //
  62. ];
  63. }
  64. public static function getPages(): array
  65. {
  66. return [
  67. 'index' => Pages\ListNewsCategories::route('/'),
  68. 'create' => Pages\CreateNewsCategory::route('/create'),
  69. 'edit' => Pages\EditNewsCategory::route('/{record}/edit'),
  70. ];
  71. }
  72. }