From 169cbe8b64162f80aa019a2cab7b12f93c05d23d Mon Sep 17 00:00:00 2001 From: Innocent Mazando Date: Fri, 27 Mar 2020 16:09:25 +0200 Subject: [PATCH] [7.x] Fixed component class view reference (#32132) * fixed component class view reference * Update ComponentMakeCommand.php Co-authored-by: Taylor Otwell --- .../Console/ComponentMakeCommand.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Foundation/Console/ComponentMakeCommand.php b/src/Illuminate/Foundation/Console/ComponentMakeCommand.php index 48c630f505cc..3bcce0d97bf1 100644 --- a/src/Illuminate/Foundation/Console/ComponentMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ComponentMakeCommand.php @@ -53,11 +53,7 @@ public function handle() */ protected function writeView() { - $view = collect(explode('/', $this->argument('name'))) - ->map(function ($part) { - return Str::kebab($part); - }) - ->implode('.'); + $view = $this->getView(); $path = resource_path('views').'/'.str_replace('.', '/', 'components.'.$view); @@ -91,11 +87,25 @@ protected function buildClass($name) return str_replace( 'DummyView', - 'view(\'components.'.Str::kebab(class_basename($name)).'\')', + 'view(\'components.'.$this->getView().'\')', parent::buildClass($name) ); } + /** + * Get the view name relative to the components directory. + * + * @return string view + */ + protected function getView() + { + return collect(explode('/', $this->argument('name'))) + ->map(function ($part) { + return Str::kebab($part); + }) + ->implode('.'); + } + /** * Get the stub file for the generator. *