From 8e9c0b622dbd06e530d0d88fe9095630e79e57cb Mon Sep 17 00:00:00 2001 From: pxpm Date: Tue, 15 Oct 2024 11:39:38 +0100 Subject: [PATCH 1/2] do not import request when not using request validation --- src/Console/Commands/CrudBackpackCommand.php | 2 +- src/Console/Commands/CrudControllerBackpackCommand.php | 7 +++++++ src/Console/stubs/crud-controller.stub | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Console/Commands/CrudBackpackCommand.php b/src/Console/Commands/CrudBackpackCommand.php index 5d1dd02..3cea032 100644 --- a/src/Console/Commands/CrudBackpackCommand.php +++ b/src/Console/Commands/CrudBackpackCommand.php @@ -73,7 +73,7 @@ public function handle() ]); // if the application uses cached routes, we should rebuild the cache so the previous added route will - // be acessible without manually clearing the route cache. + // be accessible without manually clearing the route cache. if (app()->routesAreCached()) { $this->call('route:cache'); } diff --git a/src/Console/Commands/CrudControllerBackpackCommand.php b/src/Console/Commands/CrudControllerBackpackCommand.php index 7eec3e6..c8162a8 100644 --- a/src/Console/Commands/CrudControllerBackpackCommand.php +++ b/src/Console/Commands/CrudControllerBackpackCommand.php @@ -226,6 +226,13 @@ protected function replaceRequest(&$stub) $stub = str_replace(' CRUD::setValidation(DummyClassRequest::class);'.PHP_EOL, '', $stub); } + if($validation !== 'request') { + $stub = str_replace('use App\Http\Requests\DummyModelClassRequest;', '', $stub); + }else{ + // add a new line after the use statement + $stub = str_replace('use App\Http\Requests\DummyModelClassRequest;', "use App\Http\Requests\DummyModelClassRequest;\n", $stub); + } + return $this; } diff --git a/src/Console/stubs/crud-controller.stub b/src/Console/stubs/crud-controller.stub index a5ea243..4bfff2c 100644 --- a/src/Console/stubs/crud-controller.stub +++ b/src/Console/stubs/crud-controller.stub @@ -2,10 +2,9 @@ namespace DummyNamespace; -use App\Http\Requests\DummyModelClassRequest; use Backpack\CRUD\app\Http\Controllers\CrudController; use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD; - +use App\Http\Requests\DummyModelClassRequest; /** * Class DummyClassCrudController * @package App\Http\Controllers\Admin From b2548ca6e712a0010504b07b75fbbe5ae7ee3ee8 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 15 Oct 2024 10:39:51 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/Console/Commands/CrudControllerBackpackCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/CrudControllerBackpackCommand.php b/src/Console/Commands/CrudControllerBackpackCommand.php index c8162a8..fc88e81 100644 --- a/src/Console/Commands/CrudControllerBackpackCommand.php +++ b/src/Console/Commands/CrudControllerBackpackCommand.php @@ -226,9 +226,9 @@ protected function replaceRequest(&$stub) $stub = str_replace(' CRUD::setValidation(DummyClassRequest::class);'.PHP_EOL, '', $stub); } - if($validation !== 'request') { + if ($validation !== 'request') { $stub = str_replace('use App\Http\Requests\DummyModelClassRequest;', '', $stub); - }else{ + } else { // add a new line after the use statement $stub = str_replace('use App\Http\Requests\DummyModelClassRequest;', "use App\Http\Requests\DummyModelClassRequest;\n", $stub); }