diff --git a/packages/forms/resources/views/components/form.blade.php b/packages/forms/resources/views/components/form.blade.php index dc2afcd886..e329583c5c 100644 --- a/packages/forms/resources/views/components/form.blade.php +++ b/packages/forms/resources/views/components/form.blade.php @@ -23,7 +23,7 @@ @if (count($schema))
-
+
@foreach ($schema as $component) {{ $component->render() }} @endforeach diff --git a/resources/views/resources/relation-manager/attach-record.blade.php b/resources/views/resources/relation-manager/attach-record.blade.php index 97b8538023..021c4feab9 100644 --- a/resources/views/resources/relation-manager/attach-record.blade.php +++ b/resources/views/resources/relation-manager/attach-record.blade.php @@ -11,7 +11,7 @@ color="primary" class="w-full sm:w-auto" > - {{ __($this->getManager()::$attachModalAttachButtonLabel) }} + {{ __($this->manager::$attachModalAttachButtonLabel) }} - {{ __($this->getManager()::$attachModalAttachAnotherButtonLabel) }} + {{ __($this->manager::$attachModalAttachAnotherButtonLabel) }} - {{ __($this->getManager()::$attachModalCancelButtonLabel) }} + {{ __($this->manager::$attachModalCancelButtonLabel) }}
diff --git a/resources/views/resources/relation-manager/create-record.blade.php b/resources/views/resources/relation-manager/create-record.blade.php index 3c7ca85225..76665dcab9 100644 --- a/resources/views/resources/relation-manager/create-record.blade.php +++ b/resources/views/resources/relation-manager/create-record.blade.php @@ -10,7 +10,7 @@ type="submit" color="primary" > - {{ __($this->getManager()::$createModalCreateButtonLabel) }} + {{ __($this->manager::$createModalCreateButtonLabel) }} - {{ __($this->getManager()::$createModalCreateAnotherButtonLabel) }} + {{ __($this->manager::$createModalCreateAnotherButtonLabel) }} - {{ __($this->getManager()::$createModalCancelButtonLabel) }} + {{ __($this->manager::$createModalCancelButtonLabel) }}
diff --git a/resources/views/resources/relation-manager/edit-record.blade.php b/resources/views/resources/relation-manager/edit-record.blade.php index 0eb92f367e..980d7c9161 100644 --- a/resources/views/resources/relation-manager/edit-record.blade.php +++ b/resources/views/resources/relation-manager/edit-record.blade.php @@ -10,11 +10,11 @@ type="submit" color="primary" > - {{ __($this->getManager()::$editModalSaveButtonLabel) }} + {{ __($this->manager::$editModalSaveButtonLabel) }} - {{ __($this->getManager()::$editModalCancelButtonLabel) }} + {{ __($this->manager::$editModalCancelButtonLabel) }}
diff --git a/resources/views/resources/relation-manager/list-records.blade.php b/resources/views/resources/relation-manager/list-records.blade.php index de23d74045..daa8015d24 100644 --- a/resources/views/resources/relation-manager/list-records.blade.php +++ b/resources/views/resources/relation-manager/list-records.blade.php @@ -1,29 +1,29 @@
- @if ($this->canCreate()) + @if ($this->canCreate) - {{ __($this->getManager()::$createButtonLabel) }} + {{ __($this->manager::$createButtonLabel) }} @endif - @if ($this->canAttach()) + @if ($this->canAttach) - {{ __($this->getManager()::$attachButtonLabel) }} + {{ __($this->manager::$attachButtonLabel) }} @endif - @if ($this->canDetach()) + @if ($this->canDetach) - {{ __($this->getManager()::$detachButtonLabel) }} + {{ __($this->manager::$detachButtonLabel) }} @endif - @if ($this->canDelete()) + @if ($this->canDelete) @endif
@@ -39,20 +39,20 @@ :table="$this->getTable()" /> - @if ($this->canDetach()) + @if ($this->canDetach) - +

- {{ __($this->getManager()::$detachModalDescription) }} + {{ __($this->manager::$detachModalDescription) }}

- - {{ __($this->getManager()::$detachModalCancelButtonLabel) }} + + {{ __($this->manager::$detachModalCancelButtonLabel) }} - {{ __($this->getManager()::$detachModalDetachButtonLabel) }} + {{ __($this->manager::$detachModalDetachButtonLabel) }}
diff --git a/src/Resources/Forms/Form.php b/src/Resources/Forms/Form.php index 3ca7ca24d1..6024695f24 100644 --- a/src/Resources/Forms/Form.php +++ b/src/Resources/Forms/Form.php @@ -8,6 +8,17 @@ class Form extends \Filament\Forms\Form protected $model; + public function getColumns() + { + if (! $this->hasWrapper) { + return collect(parent::getSchema()) + ->first() + ->getColumns(); + } + + return $this->columns; + } + public function getModel() { return $this->model ?? $this->getParent()->getModel(); diff --git a/src/Resources/Pages/ListRecords.php b/src/Resources/Pages/ListRecords.php index 8bec45fd5b..fba306a8d4 100644 --- a/src/Resources/Pages/ListRecords.php +++ b/src/Resources/Pages/ListRecords.php @@ -22,6 +22,16 @@ class ListRecords extends Page public static $view = 'filament::resources.pages.list-records'; + public function canCreate() + { + return Filament::can('create', static::getModel()); + } + + public function canDelete() + { + return true; + } + public function canDeleteSelected() { return static::getModel()::find($this->selected) diff --git a/src/Resources/RelationManager/AttachRecord.php b/src/Resources/RelationManager/AttachRecord.php index d37cfd763c..8b1786d595 100644 --- a/src/Resources/RelationManager/AttachRecord.php +++ b/src/Resources/RelationManager/AttachRecord.php @@ -20,11 +20,11 @@ class AttachRecord extends Component public function attach($another = false) { - $manager = $this->getManager(); + $manager = $this->manager; $this->validate(); - $this->getOwner()->{$this->getRelationshipName()}()->attach($this->getRelated()); + $this->owner->{$this->getRelationshipName()}()->attach($this->related); $this->emit('refreshRelationManagerList', $manager); @@ -45,7 +45,7 @@ class AttachRecord extends Component ->label((string) Str::of($this->getRelationshipName())->singular()->ucfirst()) ->placeholder('filament::resources/relation-manager.modals.attach.form.related.placeholder') ->getOptionSearchResultsUsing(function ($search) { - $relationship = $this->getOwner()->{$this->getRelationshipName()}(); + $relationship = $this->owner->{$this->getRelationshipName()}(); $query = $relationship->getRelated(); @@ -57,7 +57,7 @@ class AttachRecord extends Component return $query ->where($this->getPrimaryColumn(), $searchOperator, "%{$search}%") ->whereDoesntHave($this->getInverseRelationshipName(), function ($query) { - $query->where($this->getOwner()->getQualifiedKeyName(), $this->getOwner()->getKey()); + $query->where($this->owner->getQualifiedKeyName(), $this->owner->getKey()); }) ->pluck($this->getPrimaryColumn(), $query->getKeyName()) ->toArray(); @@ -68,13 +68,13 @@ class AttachRecord extends Component public function getInverseRelationshipName() { - $manager = $this->getManager(); + $manager = $this->manager; if (property_exists($manager, 'inverseRelationship')) { return $manager::$inverseRelationship; } - return (string) Str::of(class_basename($this->getOwner())) + return (string) Str::of(class_basename($this->owner)) ->lower() ->plural() ->camel(); @@ -82,36 +82,21 @@ class AttachRecord extends Component public function getPrimaryColumn() { - return $this->getManager()::getPrimaryColumn() ?? $this->getOwner()->getKeyName(); + return $this->manager::getPrimaryColumn() ?? $this->owner->getKeyName(); } public function getRelationship() { - return $this->getOwner()->{$this->getRelationshipName()}(); + return $this->owner->{$this->getRelationshipName()}(); } public function getRelationshipName() { - $manager = $this->getManager(); + $manager = $this->manager; return $manager::$relationship; } - public function getOwner() - { - return $this->owner; - } - - public function getManager() - { - return $this->manager; - } - - public function getRelated() - { - return $this->related; - } - public function mount() { $this->fillWithFormDefaults(); diff --git a/src/Resources/RelationManager/CreateRecord.php b/src/Resources/RelationManager/CreateRecord.php index 83f9edeb33..8aef168f05 100644 --- a/src/Resources/RelationManager/CreateRecord.php +++ b/src/Resources/RelationManager/CreateRecord.php @@ -20,7 +20,7 @@ class CreateRecord extends Component public function create($another = false) { - $manager = $this->getManager(); + $manager = $this->manager; $this->validateTemporaryUploadedFiles(); @@ -28,7 +28,7 @@ class CreateRecord extends Component $this->validate(); - $this->getOwner()->{$this->getRelationshipName()}()->create($this->record); + $this->owner->{$this->getRelationshipName()}()->create($this->record); $this->emit('refreshRelationManagerList', $manager); @@ -44,29 +44,14 @@ class CreateRecord extends Component protected function form(Form $form) { - return $this->getManager()::form( - $form->model(get_class($this->getOwner()->{$this->getRelationshipName()}()->getModel())), + return $this->manager::form( + $form->model(get_class($this->owner->{$this->getRelationshipName()}()->getModel())), ); } - public function getManager() - { - return $this->manager; - } - - public function getModel() - { - return $this->model; - } - - public function getOwner() - { - return $this->owner; - } - public function getRelationshipName() { - $manager = $this->getManager(); + $manager = $this->manager; return $manager::$relationship; } diff --git a/src/Resources/RelationManager/EditRecord.php b/src/Resources/RelationManager/EditRecord.php index 3335195d18..df1a1268c3 100644 --- a/src/Resources/RelationManager/EditRecord.php +++ b/src/Resources/RelationManager/EditRecord.php @@ -24,7 +24,7 @@ class EditRecord extends Component protected function form(Form $form) { - return $this->getManager()::form($form->model(get_class($this->getOwner()->{$this->getRelationshipName()}()->getModel()))); + return $this->manager::form($form->model(get_class($this->owner->{$this->getRelationshipName()}()->getModel()))); } public function getQuery() @@ -34,22 +34,12 @@ class EditRecord extends Component public function getRelationship() { - return $this->getOwner()->{$this->getRelationshipName()}(); - } - - public function getManager() - { - return $this->manager; - } - - public function getOwner() - { - return $this->owner; + return $this->owner->{$this->getRelationshipName()}(); } public function getRelationshipName() { - $manager = $this->getManager(); + $manager = $this->manager; return $manager::$relationship; } @@ -66,7 +56,7 @@ class EditRecord extends Component public function save() { - $manager = $this->getManager(); + $manager = $this->manager; abort_unless(Filament::can('update', $this->record), 403); @@ -88,7 +78,7 @@ class EditRecord extends Component public function switchRecord($manager, $record) { - if ($manager !== $this->getManager()) { + if ($manager !== $this->manager) { return; } diff --git a/src/Resources/RelationManager/ListRecords.php b/src/Resources/RelationManager/ListRecords.php index f3d9f5a1bd..47aa8ff231 100644 --- a/src/Resources/RelationManager/ListRecords.php +++ b/src/Resources/RelationManager/ListRecords.php @@ -30,29 +30,9 @@ class ListRecords extends Component 'refreshRelationManagerList' => 'refreshList', ]; - public function canAttach() - { - return $this->canAttach; - } - - public function canCreate() - { - return $this->canCreate; - } - - public function canDelete() - { - return $this->canDelete; - } - - public function canDetach() - { - return $this->canDetach; - } - public function canDeleteSelected() { - return $this->getModel()::find($this->selected) + return $this->model::find($this->selected) ->contains(function ($record) { return Filament::can('delete', $record); }); @@ -60,10 +40,10 @@ class ListRecords extends Component public function deleteSelected() { - abort_unless($this->canDelete(), 403); + abort_unless($this->canDelete, 403); - $this->getModel()::destroy( - $this->getModel()::find($this->selected) + $this->model::destroy( + $this->model::find($this->selected) ->filter(function ($record) { return Filament::can('delete', $record); }) @@ -76,39 +56,26 @@ class ListRecords extends Component public function detachSelected() { + $manager = $this->manager; + $relationship = $this->getRelationship(); $relationship->detach($this->selected); - $this->dispatchBrowserEvent('close', $this->getManager() . 'RelationManagerDetachModal'); - $this->dispatchBrowserEvent('notify', __($this->getManager()::$detachModalDetachedMessage)); + $this->dispatchBrowserEvent('close', $manager . 'RelationManagerDetachModal'); + $this->dispatchBrowserEvent('notify', __($manager::$detachModalDetachedMessage)); $this->selected = []; } - public function getManager() - { - return $this->manager; - } - - public function getModel() - { - return $this->model; - } - - public function getOwner() - { - return $this->owner; - } - public function getRelationship() { - return $this->getOwner()->{$this->getRelationshipName()}(); + return $this->owner->{$this->getRelationshipName()}(); } public function getRelationshipName() { - return $this->getManager()::getRelationshipName(); + return $this->manager::getRelationshipName(); } public function getPrimaryColumnAction($record) @@ -127,7 +94,7 @@ class ListRecords extends Component public function getRecordActions() { - $manager = $this->getManager(); + $manager = $this->manager; return [ RecordActions\Link::make('edit') @@ -144,7 +111,7 @@ class ListRecords extends Component protected function table(Table $table) { - return $this->getManager()::table( + return $this->manager::table( $table ->primaryColumnAction(function ($record) { return $this->getPrimaryColumnAction($record); @@ -155,29 +122,29 @@ class ListRecords extends Component public function openAttach() { - $this->dispatchBrowserEvent('open', $this->getManager() . 'RelationManagerAttachModal'); + $this->dispatchBrowserEvent('open', $this->manager . 'RelationManagerAttachModal'); } public function openCreate() { - $this->dispatchBrowserEvent('open', $this->getManager() . 'RelationManagerCreateModal'); + $this->dispatchBrowserEvent('open', $this->manager . 'RelationManagerCreateModal'); } public function openDetach() { - $this->dispatchBrowserEvent('open', $this->getManager() . 'RelationManagerDetachModal'); + $this->dispatchBrowserEvent('open', $this->manager . 'RelationManagerDetachModal'); } public function openEdit($record) { - $this->emit('switchRelationManagerEditRecord', $this->getManager(), $record); + $this->emit('switchRelationManagerEditRecord', $this->manager, $record); - $this->dispatchBrowserEvent('open', $this->getManager() . 'RelationManagerEditModal'); + $this->dispatchBrowserEvent('open', $this->manager . 'RelationManagerEditModal'); } public function refreshList($manager = null) { - if ($manager !== null && $manager !== $this->getManager()) { + if ($manager !== null && $manager !== $this->manager) { return; }