Filament Global Component Configuration

laracast 這篇添加可以加入 max length 的方法跟全局組件設定。 Max Length 這個設計跟原先添加設計方法大致相同: //TextInput protected int | \Closure | null $maxLength = null; public function maxLength(int | \Closure | null $length): self { $this->maxLength = $length; return $this; } public function getMaxLength(): ?int { return $this->evaluate($this->maxLength); } //text-input.blade <input type="text" maxlength="{{ $getMaxLength() }}" wire:model.live="{{ $getName() }}"/> 組件 TestForm 新增兩個來進行驗證: $nameInput = TextInput::make('name') ->maxLength(10) ->livewire($this); $emailInput = TextInput::make('email') ->maxLength(20) ->livewire($this); return view('livewire.test-form', [ 'nameInput' => $nameInput, 'emailInput' => $emailInput, ]); <div> {{ $nameInput }} {{ $emailInput }} </div> 添加 global configuration 將全局設定傳入closure 依序添加至元件內:...

December 21, 2023 · Yish

Filament Global Search

Global search 搜尋條件 以什麼欄位搜尋 // 單獨 protected static ?string $recordTitleAttribute = 'title'; // 多個 public static function getGloballySearchableAttributes(): array { return ['title', 'slug', 'author.name', 'category.name']; } 客製化搜尋結果欄位顯示,舉例來說 title = Yish 前面想要添加 author.name: public static function getGlobalSearchResultTitle(Model $record): string { return $record->author->name .':'. $record->name; } 添加更多內容在搜尋結果欄位內: public static function getGlobalSearchResultDetails(Model $record): array { return [ 'Author' => $record->author->name, 'Category' => $record->category->name, ]; } 使用何種 query 來作搜尋,這邊可以看到我們必須先 eager load author 和 category:...

October 11, 2023 · Yish