mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
wip
This commit is contained in:
@@ -778,19 +778,10 @@ Now, you can access the `status` in the relation manager class using `$this->sta
|
||||
|
||||
## Disabling lazy loading
|
||||
|
||||
By default, relation managers are lazy-loaded. This means that they will only be loaded when they are visible on the page.
|
||||
By default, relation managers are lazy-loaded. This means that they will only be loaded when they are visible on the page.
|
||||
|
||||
You can disable this behavior, using the `make()` method:
|
||||
To disable this behavior, you may override the `$isLazy` property on the relation manager class:
|
||||
|
||||
```php
|
||||
use App\Filament\Resources\Blog\PostResource\RelationManagers\CommentsRelationManager;
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
CommentsRelationManager::make([
|
||||
'lazy' => false,
|
||||
]),
|
||||
];
|
||||
}
|
||||
```
|
||||
protected static bool $isLazy = false;
|
||||
```
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
class="flex flex-col gap-y-4"
|
||||
>
|
||||
@php
|
||||
$managerLivewireProperties = ['lazy' => true, 'ownerRecord' => $ownerRecord, 'pageClass' => $pageClass];
|
||||
$managerLivewireProperties = ['ownerRecord' => $ownerRecord, 'pageClass' => $pageClass];
|
||||
|
||||
if (filled($activeLocale)) {
|
||||
$managerLivewireProperties['activeLocale'] = $activeLocale;
|
||||
@@ -86,7 +86,7 @@
|
||||
|
||||
@livewire(
|
||||
$normalizedGroupedManagerClass,
|
||||
[...$managerLivewireProperties, ...(($groupedManager instanceof \Filament\Resources\RelationManagers\RelationManagerConfiguration) ? $groupedManager->properties : [])],
|
||||
[...$managerLivewireProperties, ...(($groupedManager instanceof \Filament\Resources\RelationManagers\RelationManagerConfiguration) ? [...$groupedManager->relationManager::getDefaultProperties(), ...$groupedManager->properties] : $groupedManager::getDefaultProperties())],
|
||||
key($normalizedGroupedManagerClass),
|
||||
)
|
||||
@endforeach
|
||||
@@ -98,7 +98,7 @@
|
||||
|
||||
@livewire(
|
||||
$normalizedManagerClass,
|
||||
[...$managerLivewireProperties, ...(($manager instanceof \Filament\Resources\RelationManagers\RelationManagerConfiguration) ? $manager->properties : [])],
|
||||
[...$managerLivewireProperties, ...(($manager instanceof \Filament\Resources\RelationManagers\RelationManagerConfiguration) ? [...$manager->relationManager::getDefaultProperties(), ...$manager->properties] : $manager::getDefaultProperties())],
|
||||
key($normalizedManagerClass),
|
||||
)
|
||||
@endif
|
||||
|
||||
@@ -82,6 +82,8 @@ class RelationManager extends Component implements Actions\Contracts\HasActions,
|
||||
|
||||
protected static ?string $badge = null;
|
||||
|
||||
protected static bool $isLazy = true;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->loadDefaultActiveTab();
|
||||
@@ -504,4 +506,23 @@ class RelationManager extends Component implements Actions\Contracts\HasActions,
|
||||
fn (Table $table, ?Closure $using) => $table->recordUrl($using),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function getDefaultProperties(): array
|
||||
{
|
||||
$properties = [];
|
||||
|
||||
if (static::isLazy()) {
|
||||
$properties['lazy'] = true;
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
public static function isLazy(): bool
|
||||
{
|
||||
return static::$isLazy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
@foreach ($widgets as $key => $widget)
|
||||
@livewire(
|
||||
$normalizeWidgetClass($widget),
|
||||
[...(($widget instanceof \Filament\Widgets\WidgetConfiguration) ? $widget->properties : $widget::getDefaultProperties()), ...$data],
|
||||
[...(($widget instanceof \Filament\Widgets\WidgetConfiguration) ? [...$widget->widget::getDefaultProperties(), ...$widget->properties] : $widget::getDefaultProperties()), ...$data],
|
||||
key($key),
|
||||
)
|
||||
@endforeach
|
||||
|
||||
Reference in New Issue
Block a user