From b5df5de1bcd1f3e401356bc123b7b89281d9dd9e Mon Sep 17 00:00:00 2001 From: Pedro X Date: Wed, 9 Aug 2023 15:10:44 +0100 Subject: [PATCH 1/4] try non-bc approach --- .../Controllers/Operations/ShowOperation.php | 21 ++++++++++++------- src/config/backpack/operations/show.php | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/app/Http/Controllers/Operations/ShowOperation.php b/src/app/Http/Controllers/Operations/ShowOperation.php index 1071c14199..ec27de681b 100644 --- a/src/app/Http/Controllers/Operations/ShowOperation.php +++ b/src/app/Http/Controllers/Operations/ShowOperation.php @@ -75,16 +75,23 @@ public function show($id) // get entry ID from Request (makes sure its the last ID for nested resources) $id = $this->crud->getCurrentEntryId() ?? $id; - // get the info for that entry (include softDeleted items if the trait is used) - if ($this->crud->get('show.softDeletes') && in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($this->crud->model))) { - $this->data['entry'] = $this->crud->getModel()->withTrashed()->findOrFail($id); - } else { - $this->data['entry'] = $this->crud->getEntryWithLocale($id); - } - $this->data['crud'] = $this->crud; $this->data['title'] = $this->crud->getTitle() ?? trans('backpack::crud.preview').' '.$this->crud->entity_name; + // get the info for that entry (include softDeleted items if the trait is used) + if (! $this->crud->get('show.softDeletes') || ! in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($this->crud->model))) { + $this->data['entry'] = $this->crud->getEntryWithLocale($id); + return view($this->crud->getShowView(), $this->data); + } + + if($this->crud->get('show.usePanelQuery')) { + $this->data['entry'] = $this->crud->query->withTrashed()->findOrFail($id); + $this->data['entry'] = $this->crud->setLocaleOnModel($this->data['entry']); + return view($this->crud->getShowView(), $this->data); + } + + $this->data['entry'] = $this->crud->getModel()->withTrashed()->findOrFail($id); + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package return view($this->crud->getShowView(), $this->data); } diff --git a/src/config/backpack/operations/show.php b/src/config/backpack/operations/show.php index f7fb4c0426..4546630700 100644 --- a/src/config/backpack/operations/show.php +++ b/src/config/backpack/operations/show.php @@ -26,4 +26,6 @@ // When using tabbed forms (create & update), what kind of tabs would you like? 'tabsType' => 'horizontal', //options: horizontal, vertical + + 'usePanelQuery' => false, ]; From c4f5a05176fdea37ddb5635dd17115540d8d300a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 9 Aug 2023 14:10:59 +0000 Subject: [PATCH 2/4] Apply fixes from StyleCI [ci skip] [skip ci] --- src/app/Http/Controllers/Operations/ShowOperation.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/Http/Controllers/Operations/ShowOperation.php b/src/app/Http/Controllers/Operations/ShowOperation.php index ec27de681b..9f9cc93edf 100644 --- a/src/app/Http/Controllers/Operations/ShowOperation.php +++ b/src/app/Http/Controllers/Operations/ShowOperation.php @@ -81,17 +81,19 @@ public function show($id) // get the info for that entry (include softDeleted items if the trait is used) if (! $this->crud->get('show.softDeletes') || ! in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($this->crud->model))) { $this->data['entry'] = $this->crud->getEntryWithLocale($id); + return view($this->crud->getShowView(), $this->data); } - - if($this->crud->get('show.usePanelQuery')) { + + if ($this->crud->get('show.usePanelQuery')) { $this->data['entry'] = $this->crud->query->withTrashed()->findOrFail($id); $this->data['entry'] = $this->crud->setLocaleOnModel($this->data['entry']); + return view($this->crud->getShowView(), $this->data); } - + $this->data['entry'] = $this->crud->getModel()->withTrashed()->findOrFail($id); - + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package return view($this->crud->getShowView(), $this->data); } From 147dde2ade6cbbc06670b919bdc01b6c918701b0 Mon Sep 17 00:00:00 2001 From: Pedro X Date: Wed, 9 Aug 2023 16:35:29 +0100 Subject: [PATCH 3/4] add descriptions --- src/app/Http/Controllers/Operations/ShowOperation.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/Http/Controllers/Operations/ShowOperation.php b/src/app/Http/Controllers/Operations/ShowOperation.php index 9f9cc93edf..f1f7772141 100644 --- a/src/app/Http/Controllers/Operations/ShowOperation.php +++ b/src/app/Http/Controllers/Operations/ShowOperation.php @@ -85,8 +85,12 @@ public function show($id) return view($this->crud->getShowView(), $this->data); } + // when enabled we will call the findOrFail() directly in the crud panel query, instead of the model query. + // this allow developers to setup constrains on the query that can be applied in multiple operations. if ($this->crud->get('show.usePanelQuery')) { $this->data['entry'] = $this->crud->query->withTrashed()->findOrFail($id); + // we will miss the "magic __call() to findOrFail" in the model when it's translatable, + // so we need to manually set the locale when needed. $this->data['entry'] = $this->crud->setLocaleOnModel($this->data['entry']); return view($this->crud->getShowView(), $this->data); From eb93371189160cccd677a2731d0eddbf30221efe Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 9 Aug 2023 15:35:42 +0000 Subject: [PATCH 4/4] Apply fixes from StyleCI [ci skip] [skip ci] --- src/app/Http/Controllers/Operations/ShowOperation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Http/Controllers/Operations/ShowOperation.php b/src/app/Http/Controllers/Operations/ShowOperation.php index f1f7772141..e5f185f436 100644 --- a/src/app/Http/Controllers/Operations/ShowOperation.php +++ b/src/app/Http/Controllers/Operations/ShowOperation.php @@ -89,7 +89,7 @@ public function show($id) // this allow developers to setup constrains on the query that can be applied in multiple operations. if ($this->crud->get('show.usePanelQuery')) { $this->data['entry'] = $this->crud->query->withTrashed()->findOrFail($id); - // we will miss the "magic __call() to findOrFail" in the model when it's translatable, + // we will miss the "magic __call() to findOrFail" in the model when it's translatable, // so we need to manually set the locale when needed. $this->data['entry'] = $this->crud->setLocaleOnModel($this->data['entry']);