From 13ff9bff6d8eb66af7dc57908b5682b6bd39f389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seleziomar=20J=C3=BAnior?= Date: Fri, 7 Apr 2023 18:25:43 -0300 Subject: [PATCH] small-feature: adding control if the create button will be displayed in ListScreen --- src/Resource.php | 9 +++++++++ src/Screens/ListScreen.php | 17 ++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Resource.php b/src/Resource.php index 6c16766..d88ef7a 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -145,6 +145,15 @@ public static function nameWithoutResource(): string return 'Resource'; }); } + /** + * Get the Create Button should be displayed in the ListScreen + * + * @return string|null + */ + public static function displayCreateButtonInList(): bool + { + return true; + } /** * Get the text for the create resource button. diff --git a/src/Screens/ListScreen.php b/src/Screens/ListScreen.php index 76829fb..7c4515f 100644 --- a/src/Screens/ListScreen.php +++ b/src/Screens/ListScreen.php @@ -35,13 +35,16 @@ public function query(IndexRequest $request): array */ public function commandBar(): array { - return [ - $this->actionsButtons(), - Link::make($this->resource::createButtonLabel()) - ->route('platform.resource.create', $this->resource::uriKey()) - ->canSee($this->can('create')) - ->icon('plus'), - ]; + $actions[] = $this->actionsButtons(); + + if($this->resource::displayCreateButtonInList()){ + $actions[] = Link::make($this->resource::createButtonLabel()) + ->route('platform.resource.create', $this->resource::uriKey()) + ->canSee($this->can('create')) + ->icon('plus'); + } + + return $actions; } /**