Skip to content

Commit

Permalink
fix: Issue (HasMany resource item)
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Oct 11, 2024
1 parent 699cf28 commit 1e7b3da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Fields/Relationships/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ protected function tableValue(): MoonShineRenderable
protected function getItemButtons(): array
{
$resource = $this->getResource();
$resource->stopGettingItemFromUrl();

$redirectAfter = $this->isAsync()
? ''
Expand Down
13 changes: 13 additions & 0 deletions src/Traits/Resource/ResourceModelQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,20 @@ trait ResourceModelQuery

protected int|string|null $itemID = null;

protected bool $stopGettingItemFromUrl = false;

protected array $parentRelations = [];

// TODO 3.0 rename to saveQueryState
protected bool $saveFilterState = false;

public function stopGettingItemFromUrl(): static
{
$this->stopGettingItemFromUrl = true;

return $this;
}

public function setItemID(int|string|null $itemID): static
{
$this->itemID = $itemID;
Expand Down Expand Up @@ -101,6 +110,10 @@ public function getItem(): ?Model
return null;
}

if($this->stopGettingItemFromUrl && blank($this->itemID)) {
return null;
}

return $this->itemOr(
fn () => $this
->resolveItemQuery()
Expand Down

0 comments on commit 1e7b3da

Please sign in to comment.