Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

Filament Relation Manager: Hide on View/Edit Page?

Filament relation manager is a great feature for showing data from an Eloquent relationship. But what if you want to show the relation manager only on the View page but not Edit?

Imagine a scenario: we have Items resource and want to show Transactions only on the view page.

I will show you two options.


Option 1: Remove Managers from Edit Page

When you register Relation Managers in the Resource, they are shown in the Edit and View pages.

class ItemResource extends Resource
{
// ..
 
public static function getRelations(): array
{
return [
ItemResource\RelationManagers\TransactionsRelationManager::class,
];
}
 
// ...
}

You can remove Relation Managers from the Edit page by returning an empty array using the getRelationManagers() method on the Edit page class.

class EditItem extends EditRecord
{
// ...
 
public function getRelationManagers(): array
{
return [];
}
}

Option 2: Add on the Page and not Resource

Another way to show the Relation Manager only on the View page is to register it on the page class instead of a Resource. The manager can be registered on the Edit or List pages class to show the Relation Manager only on the View page.

On the view class:

use App\Filament\Resources\ItemResource\RelationManagers\TransactionsRelationManager;
 
class ViewItem extends ViewRecord
{
protected static string $resource = ItemResource::class;
 
public function getRelationManagers(): array
{
return [
TransactionsRelationManager::class,
];
}
 
// ...
}

Or on the list class:

use App\Filament\Resources\ItemResource\RelationManagers\TransactionsRelationManager;
 
class ListItems extends ListRecords
{
// ...
 
public function getRelationManagers(): array
{
return [
TransactionsRelationManager::class,
];
}
}

If you want more Filament examples, you can find more real-life projects on our FilamentExamples.com.

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses