Skip to main content
Tutorial Free

Filament Relation Manager: Hide on View/Edit Page?

May 10, 2024
2 min read

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.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.