mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Store table on group
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Tables\Grouping\Concerns;
|
||||
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
trait BelongsToTable
|
||||
{
|
||||
protected Table $table;
|
||||
|
||||
public function table(Table $table): static
|
||||
{
|
||||
$this->table = $table;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTable(): Table
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function getLivewire(): HasTable
|
||||
{
|
||||
return $this->getTable()->getLivewire();
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ use Illuminate\Support\Arr;
|
||||
|
||||
class Group extends Component
|
||||
{
|
||||
use Concerns\BelongsToTable;
|
||||
|
||||
protected ?string $column;
|
||||
|
||||
protected ?Closure $getDescriptionFromRecordUsing = null;
|
||||
@@ -33,7 +35,7 @@ class Group extends Component
|
||||
|
||||
protected ?Closure $scopeQueryByKeyUsing = null;
|
||||
|
||||
protected string | Closure | null $label;
|
||||
protected string | Closure | null $label = null;
|
||||
|
||||
protected string $id;
|
||||
|
||||
@@ -471,4 +473,16 @@ class Group extends Component
|
||||
|
||||
return $query->with([$relationshipName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
protected function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array
|
||||
{
|
||||
return match ($parameterName) {
|
||||
'livewire' => [$this->getLivewire()],
|
||||
'table' => [$this->getTable()],
|
||||
default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ trait CanGroupRecords
|
||||
|
||||
public function defaultGroup(string | Group | null $group): static
|
||||
{
|
||||
if ($group instanceof Group) {
|
||||
$group->table($this);
|
||||
}
|
||||
|
||||
$this->defaultGroup = $group;
|
||||
|
||||
return $this;
|
||||
@@ -82,6 +86,12 @@ trait CanGroupRecords
|
||||
*/
|
||||
public function groups(array | Closure $groups): static
|
||||
{
|
||||
foreach ($groups as $group) {
|
||||
if ($group instanceof Group) {
|
||||
$group->table($this);
|
||||
}
|
||||
}
|
||||
|
||||
$this->groups = $groups;
|
||||
|
||||
return $this;
|
||||
@@ -159,7 +169,8 @@ trait CanGroupRecords
|
||||
return $group;
|
||||
}
|
||||
|
||||
return Group::make($this->defaultGroup);
|
||||
return Group::make($this->defaultGroup)
|
||||
->table($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +182,8 @@ trait CanGroupRecords
|
||||
$this->evaluate($this->groups),
|
||||
function (array $carry, $group): array {
|
||||
if (! $group instanceof Group) {
|
||||
$group = Group::make($group);
|
||||
$group = Group::make($group)
|
||||
->table($this);
|
||||
}
|
||||
|
||||
$carry[$group->getId()] = $group;
|
||||
|
||||
Reference in New Issue
Block a user