Skip to content

Commit

Permalink
Added support for nested resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Jehizkia committed Jul 1, 2024
1 parent b2be2a5 commit 619f1e4
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/Resources/Pages/Concerns/UsesRelationManagerResourceLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ trait UsesRelationManagerResourceLock

public function bootUsesRelationManagerResourceLock(): void
{
$this->parentClass =
"App\\Models\\" .
class_basename($this->getRelationship()->getParent());

$this->relatedClass =
"App\\Models\\" .
class_basename($this->getRelationship()->getRelated());
$this->parentClass = get_class($this->getRelationship()->getParent());
$this->relatedClass = get_class($this->getRelationship()->getRelated());
}

#[On('resourceLockObserver::unlock')]
public function resourceLockObserverUnlock(){
public function resourceLockObserverUnlock()
{
if ($this->relatedRecord) {
if ($this->relatedRecord->unlock(force: true)) {
$this->closeLockedResourceModal();
Expand Down Expand Up @@ -59,7 +55,7 @@ public function mountTableAction(
): mixed {
parent::mountTableAction($name, $record);

if ($name == "edit") {
if ($name == 'edit') {
$this->relatedRecord = $this->relatedClass::find($record);
$this->checkIfResourceLockHasExpired($this->relatedRecord);
$this->lockResource($this->relatedRecord);
Expand All @@ -84,9 +80,9 @@ public function unmountTableAction(

public function resourceLockReturnUrl()
{
$parentClassResource = "App\\Filament\\Resources\\" .
class_basename($this->getRelationship()->getParent()) . "Resource";
return $parentClassResource::getUrl("edit", ['record' => $this->getOwnerRecord()->id]);
$parentClassResource = Filament::getCurrentPanel()->getModelResource($this->getRelationship()->getParent());

return $parentClassResource::getUrl('edit', ['record' => $this->getOwnerRecord()->id]);
}

public function getResourceLockOwner(): void
Expand Down

0 comments on commit 619f1e4

Please sign in to comment.