name; } public static function form(Schema $schema): Schema { return $schema->components([ Section::make() ->columns(2) ->schema([ // A proper noun: an association is called what it is called // in every language, so this is not translated. TextInput::make('name') ->label(__('panel.clients.fields.name')) ->required() ->maxLength(255) ->live(onBlur: true) ->afterStateUpdated(function (?string $state, callable $get, callable $set) { if (blank($get('slug'))) { $set('slug', Str::slug((string) $state)); } }), TextInput::make('slug') ->label(__('panel.clients.fields.slug')) ->required() ->maxLength(255) ->rules(fn ($record) => [ Rule::unique('clients', 'slug')->ignore($record?->id), ]), TextInput::make('url') ->label(__('panel.clients.fields.url')) ->url() ->maxLength(2048) ->columnSpanFull(), FileUpload::make('logo') ->label(__('panel.clients.fields.logo')) ->image() ->disk(config('media.disk')) ->directory('clients') ->helperText(__('panel.clients.fields.logo_hint')) ->columnSpanFull(), TranslatableTabs::make(fn (string $locale) => [ TextInput::make("sector.{$locale}") ->label(__('panel.clients.fields.sector')) ->maxLength(120) ->columnSpanFull(), ])->columnSpanFull(), Toggle::make('is_public') ->label(__('panel.clients.fields.is_public')) // Not everybody wants to appear on somebody else's // website, and that is their call, not ours. ->helperText(__('panel.clients.fields.is_public_hint')) ->default(true), TextInput::make('position') ->label(__('panel.clients.fields.position')) ->numeric() ->default(0), ]), ]); } public static function table(Table $table): Table { return $table ->defaultSort('position') ->reorderable('position') ->columns([ ImageColumn::make('logo') ->label('') ->disk(config('media.disk')) ->height(32), TextColumn::make('name') ->label(__('panel.clients.fields.name')) ->weight('medium') ->description(fn (Client $record) => $record->getTranslation('sector', app()->getLocale(), false) ?: null) ->searchable() ->sortable(), TextColumn::make('projects_count') ->label(__('panel.clients.fields.projects')) ->counts('projects') ->badge() ->color('gray'), IconColumn::make('is_public') ->label(__('panel.clients.fields.is_public')) ->boolean(), TextColumn::make('url') ->label(__('panel.clients.fields.url')) ->url(fn (Client $record) => $record->url) ->openUrlInNewTab() ->placeholder('—') ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ TernaryFilter::make('is_public')->label(__('panel.clients.fields.is_public')), // A client with no logo is a hole in the wall of logos. Filter::make('without_logo') ->label(__('panel.clients.filters.without_logo')) ->query(fn (Builder $query) => $query->whereNull('logo')), TrashedFilter::make(), ]) ->recordActions([ EditAction::make(), DeleteAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), ForceDeleteBulkAction::make(), RestoreBulkAction::make(), ]), ]); } /** * @return array */ public static function getGloballySearchableAttributes(): array { return ['name']; } public static function getRelations(): array { return [ RevisionsRelationManager::class, ]; } public static function getPages(): array { return [ 'index' => ListClients::route('/'), 'create' => CreateClient::route('/create'), 'edit' => EditClient::route('/{record}/edit'), ]; } }