diff --git a/src/Contracts/src/Core/CrudResourceContract.php b/src/Contracts/src/Core/CrudResourceContract.php index 0b324a25c..94b963a32 100644 --- a/src/Contracts/src/Core/CrudResourceContract.php +++ b/src/Contracts/src/Core/CrudResourceContract.php @@ -140,6 +140,16 @@ public function getDetailPageUrl( null|string|array $fragment = null ): string; + public function isIndexPage(): bool; + + public function isFormPage(): bool; + + public function isDetailPage(): bool; + + public function isCreateFormPage(): bool; + + public function isUpdateFormPage(): bool; + public function setQueryParams(iterable $params): static; public function getQueryParams(): Collection; diff --git a/src/Laravel/src/Resources/CrudResource.php b/src/Laravel/src/Resources/CrudResource.php index 170260f34..edef3e3d5 100644 --- a/src/Laravel/src/Resources/CrudResource.php +++ b/src/Laravel/src/Resources/CrudResource.php @@ -146,6 +146,11 @@ public function getIndexPage(): ?PageContract return $this->getPages()->indexPage(); } + public function isIndexPage(): bool + { + return $this->getActivePage() instanceof IndexPage; + } + /** * @return null|PageContract|FormPage */ @@ -154,6 +159,21 @@ public function getFormPage(): ?PageContract return $this->getPages()->formPage(); } + public function isFormPage(): bool + { + return $this->getActivePage() instanceof FormPage; + } + + public function isCreateFormPage(): bool + { + return $this->isFormPage() && \is_null($this->getItemID()); + } + + public function isUpdateFormPage(): bool + { + return $this->isFormPage() && !\is_null($this->getItemID()); + } + public function getActivePage(): ?PageContract { return $this->getPages()->activePage(); @@ -167,6 +187,11 @@ public function getDetailPage(): ?PageContract return $this->getPages()->detailPage(); } + public function isDetailPage(): bool + { + return $this->getActivePage() instanceof DetailPage; + } + public function getCaster(): DataCasterContract { return new MixedDataCaster($this->casterKeyName);