Skip to content

Instantly share code, notes, and snippets.

@sohaibafifi
Last active August 23, 2022 08:56
Show Gist options
  • Select an option

  • Save sohaibafifi/2672783b12cc794812ac41e85148c5c7 to your computer and use it in GitHub Desktop.

Select an option

Save sohaibafifi/2672783b12cc794812ac41e85148c5c7 to your computer and use it in GitHub Desktop.
<?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())),
]),
...
@php
$manager = $getManager();
@endphp
@livewire(\Livewire\Livewire::getAlias($manager, $manager::getName()), [
'ownerRecord' => $getParentRecord(),
'pageClass' => 'static::class'
],
key($manager))
<?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);
}
}
<?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