mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
wip
This commit is contained in:
@@ -162,16 +162,6 @@ Related records will be listed in a table. The entire relation manager is based
|
||||
|
||||
You may use any features of the [Table Builder](../../tables) to customize relation managers.
|
||||
|
||||
### Changing the table heading
|
||||
|
||||
The table heading is derived from the related model's name by default. In version 2 you could change the table heading by overriding `$modelLabel` or `$pluralModelLabel`, but these properties are deprecated in version 3. In version 3, you have a few ways of changing the table heading. One way is to override the `$title` attribute on the `RelationManager`:
|
||||
|
||||
```php
|
||||
protected static ?string $title = 'Approved Comments';
|
||||
```
|
||||
|
||||
Another way is to modify the `Table` by passing a string to `heading` or passing a full view to replace the entire header to `header` methods. For more information refer to [Tables](../../tables/getting-started#changing-the-table-heading) section.
|
||||
|
||||
### Listing with pivot attributes
|
||||
|
||||
For `BelongsToMany` and `MorphToMany` relationships, you may also add pivot table attributes. For example, if you have a `TeamsRelationManager` for your `UserResource`, and you want to add the `role` pivot attribute to the table, you can use:
|
||||
@@ -717,6 +707,40 @@ public function table(Table $table): Table
|
||||
}
|
||||
```
|
||||
|
||||
## Customizing the relation manager title
|
||||
|
||||
To set the title of the relation manager, you can use the `$title` property on the relation manager class:
|
||||
|
||||
```php
|
||||
protected static string $title = 'Posts';
|
||||
```
|
||||
|
||||
To set the title of the relation manager dynamically, you can override the `getTitle()` method on the relation manager class:
|
||||
|
||||
```php
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
public static function getTitle(Model $ownerRecord, string $pageClass): string
|
||||
{
|
||||
return __('relation-managers.posts.title');
|
||||
}
|
||||
```
|
||||
|
||||
The title will be reflected in the [heading of the table](../../tables/advanced#customizing-the-table-header), as well as the relation manager tab if there is more than one. If you want to customize the table heading independently, you can still use the `$table->heading()` method:
|
||||
|
||||
```php
|
||||
use Filament\Tables;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->heading('Posts')
|
||||
->columns([
|
||||
// ...
|
||||
]);
|
||||
}
|
||||
```
|
||||
|
||||
## Customizing the relation manager record title
|
||||
|
||||
The relation manager uses the concept of a "record title attribute" to determine which attribute of the related model should be used to identify it. When creating a relation manager, this attribute is passed as the third argument to the `make:filament-relation-manager` command:
|
||||
|
||||
@@ -165,38 +165,6 @@ We also define a bulk action. When bulk actions are defined, each row in the tab
|
||||
|
||||
Actions can also open modals to request confirmation from the user, as well as render forms inside to collect extra data. It's a good idea to read the [Actions documentation](../actions/overview) to learn more about their extensive capabilities throughout Filament.
|
||||
|
||||
## Changing the table heading
|
||||
|
||||
The table heading is derived from the model's name by default. If you need to change the table heading you can use the `heading` method on the table to pass a `string`, or an `Htmlable`, or a `Closure` that returns either of these.
|
||||
|
||||
```php
|
||||
use Filament\Tables\Table;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->heading('Clients')
|
||||
->columns([
|
||||
// ...
|
||||
]);
|
||||
```
|
||||
|
||||
You can also pass a full view to the `header` method, which will replace the whole header, not just the heading label.
|
||||
|
||||
```php
|
||||
use Filament\Tables\Table;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->header(view('partials.table-header', [
|
||||
'heading' => 'Clients',
|
||||
]))
|
||||
->columns([
|
||||
// ...
|
||||
]);
|
||||
```
|
||||
|
||||
## Next steps with the Table Builder package
|
||||
|
||||
Now you've finished reading this guide, where to next? Here are some suggestions:
|
||||
|
||||
@@ -195,6 +195,53 @@ public function table(Table $table): Table
|
||||
|
||||
<AutoScreenshot name="tables/reordering/custom-trigger-action" alt="Table with reorderable rows and a custom trigger action" version="3.x" />
|
||||
|
||||
## Customizing the table header
|
||||
|
||||
You can add a heading to a table using the `$table->heading()` method:
|
||||
|
||||
```php
|
||||
use Filament\Tables\Table;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->heading('Clients')
|
||||
->columns([
|
||||
// ...
|
||||
]);
|
||||
```
|
||||
|
||||
You can also add a description below the heading using the `$table->description()` method:
|
||||
|
||||
```php
|
||||
use Filament\Tables\Table;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->heading('Clients')
|
||||
->description('Manage your clients here.')
|
||||
->columns([
|
||||
// ...
|
||||
]);
|
||||
```
|
||||
|
||||
You can pass a view to the `$table->header()` method to customize the entire header:
|
||||
|
||||
```php
|
||||
use Filament\Tables\Table;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->header(view('tables.header', [
|
||||
'heading' => 'Clients',
|
||||
]))
|
||||
->columns([
|
||||
// ...
|
||||
]);
|
||||
```
|
||||
|
||||
## Polling table content
|
||||
|
||||
You may poll table content so that it refreshes at a set interval, using the `$table->poll()` method:
|
||||
|
||||
Reference in New Issue
Block a user