Last active
August 23, 2022 08:56
-
-
Save sohaibafifi/2672783b12cc794812ac41e85148c5c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| .... | |
| Forms\Components\Tabs\Tab::make('teams') | |
| ->icon('heroicon-o-user-group') | |
| ->schema([ | |
| RelationManagerTable::make('teams') | |
| ->manager(ProjectResource\RelationManagers\TeamsRelationManager::class) | |
| ->parentRecord(fn ($livewire) => ($livewire->getRecord())), | |
| ]), | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @php | |
| $manager = $getManager(); | |
| @endphp | |
| @livewire(\Livewire\Livewire::getAlias($manager, $manager::getName()), [ | |
| 'ownerRecord' => $getParentRecord(), | |
| 'pageClass' => 'static::class' | |
| ], | |
| key($manager)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Filament\Forms\Components; | |
| use Closure; | |
| use Filament\Forms\Components\Field; | |
| use Illuminate\Database\Eloquent\Model; | |
| use Filament\Forms\Components\Concerns\HasExtraInputAttributes; | |
| class RelationManagerTable extends Field | |
| { | |
| use HasExtraInputAttributes; | |
| protected string $view = 'filament.components.relation-manager'; | |
| protected string|Closure $relation_manager = ''; | |
| public Model|null|Closure $parentRecord = null; | |
| public function parentRecord(Model|Closure|null $model = null): static | |
| { | |
| $this->parentRecord = $model; | |
| return $this; | |
| } | |
| public function getParentRecord(): ?Model | |
| { | |
| $record = $this->evaluate($this->parentRecord); | |
| if ($record instanceof Model) { | |
| return $record; | |
| } | |
| return null; | |
| } | |
| public function manager(string|Closure $relation_manager): static | |
| { | |
| $this->relation_manager = $relation_manager; | |
| return $this; | |
| } | |
| public function getManager(): string | |
| { | |
| return (string) $this->evaluate($this->relation_manager); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class TeamsRelationManager extends RelationManager | |
| { | |
| .... | |
| public static function getTitle(): string | |
| { | |
| return ''; // title is already in the tab header | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment