Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to disable RelationManager list edit action #318

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 15 additions & 13 deletions resources/views/relation-manager.blade.php
Expand Up @@ -33,20 +33,22 @@ class="w-full max-w-4xl"
</x-filament::modal>
@endif

<x-filament::modal
class="w-full max-w-4xl"
:name="static::class . 'RelationManagerEditModal'"
>
<x-filament::card class="space-y-5">
<x-filament::card-header :title="static::$editModalHeading" />
@if ($this->canEdit())
<x-filament::modal
class="w-full max-w-4xl"
:name="static::class . 'RelationManagerEditModal'"
>
<x-filament::card class="space-y-5">
<x-filament::card-header :title="static::$editModalHeading" />

@livewire(static::getComponent('edit'), [
'manager' => static::class,
'model' => $this->getModel(),
'owner' => $this->getOwner(),
])
</x-filament::card>
</x-filament::modal>
@livewire(static::getComponent('edit'), [
'manager' => static::class,
'model' => $this->getModel(),
'owner' => $this->getOwner(),
])
</x-filament::card>
</x-filament::modal>
@endif

@if ($this->canAttach())
<x-filament::modal
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/RelationManager.php
Expand Up @@ -84,6 +84,11 @@ public function canCreate()
return Filament::can('create', $this->getModel());
}

public function canEdit()
{
return true;
}

public function canDelete()
{
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/RelationManager/ListRecords.php
Expand Up @@ -95,11 +95,13 @@ public function getRecordActions()
{
$manager = $this->manager;

$canEdit = (new $manager)->canEdit();

return [
RecordActions\Link::make('edit')
->label($manager::$editRecordActionLabel)
->action('openEdit')
->when(fn ($record) => Filament::can('update', $record)),
->when(fn ($record) => $canEdit && Filament::can('update', $record)),
];
}

Expand Down