From 75b2ac80a823d08197dbb4a7c1ab18d2be6c26de Mon Sep 17 00:00:00 2001 From: pxpm Date: Mon, 27 Jan 2025 15:53:36 +0000 Subject: [PATCH 1/5] next version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d67a6fd..e54fb1f 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } ], "require": { - "backpack/crud": "^6.0" + "backpack/crud": "7.0.0-alpha.1" }, "autoload": { "psr-4": { From fa29b49290899cb42f11411b5cf021b17b603ebd Mon Sep 17 00:00:00 2001 From: Pedro Martins Date: Wed, 5 Mar 2025 16:05:27 +0000 Subject: [PATCH 2/5] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e54fb1f..f8c37e3 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } ], "require": { - "backpack/crud": "7.0.0-alpha.1" + "backpack/crud": "^7.0.0-alpha" }, "autoload": { "psr-4": { From b7d386c20edde1f16579691ab8280d4da44f27a0 Mon Sep 17 00:00:00 2001 From: Cristian Tabacitu Date: Wed, 25 Jun 2025 13:57:41 +0300 Subject: [PATCH 3/5] add chip command --- .../Commands/Views/ChipBackpackCommand.php | 162 ++++++++++++++++++ src/Console/stubs/chip.stub | 29 ++++ src/GeneratorsServiceProvider.php | 2 + 3 files changed, 193 insertions(+) create mode 100644 src/Console/Commands/Views/ChipBackpackCommand.php create mode 100644 src/Console/stubs/chip.stub diff --git a/src/Console/Commands/Views/ChipBackpackCommand.php b/src/Console/Commands/Views/ChipBackpackCommand.php new file mode 100644 index 0000000..23afb5d --- /dev/null +++ b/src/Console/Commands/Views/ChipBackpackCommand.php @@ -0,0 +1,162 @@ +setupChipSourceFile(); + + if ($this->sourceFile === false) { + return false; + } + + $name = Str::of($this->getNameInput()); + $path = Str::of($this->getPath($name)); + $pathRelative = $path->after(base_path())->replace('\\', '/')->trim('/'); + + $this->infoBlock("Creating {$name->replace('_', ' ')->title()} {$this->type}"); + $this->progressBlock("Creating view {$pathRelative}"); + + if ($this->alreadyExists($name)) { + $this->closeProgressBlock('Already existed', 'yellow'); + + return false; + } + + $this->makeDirectory($path); + + if ($this->sourceFile) { + $this->files->copy($this->sourceFile, $path); + } else { + $this->files->put($path, $this->buildClass($name)); + } + + $this->closeProgressBlock(); + } + + /** + * Setup the source file for the --from option. + * This method extends the parent functionality to also look in vendor chip directories. + */ + private function setupChipSourceFile() + { + if ($this->option('from')) { + $from = $this->option('from'); + + // First, try the standard view namespaces (parent behavior) + $namespaces = ViewNamespaces::getFor($this->viewNamespace); + foreach ($namespaces as $namespace) { + $viewPath = "$namespace.$from"; + + if (view()->exists($viewPath)) { + $this->sourceFile = view($viewPath)->getPath(); + $this->sourceViewNamespace = $viewPath; + return; + } + } + + // Second, check vendor chip directory + $vendorChipPath = base_path("vendor/backpack/crud/src/resources/views/crud/chips/{$from}.blade.php"); + if (file_exists($vendorChipPath)) { + $this->sourceFile = $vendorChipPath; + // Don't set sourceViewNamespace so it uses the default path logic + return; + } + + // Third, try full or relative file paths (parent behavior) + if (file_exists($from)) { + $this->sourceFile = realpath($from); + return; + } + // remove the first slash to make absolute paths relative in unix systems + elseif (file_exists(substr($from, 1))) { + $this->sourceFile = realpath(substr($from, 1)); + return; + } + + // If nothing found, show error + $this->errorProgressBlock(); + $this->note("$this->type '$from' does not exist!", 'red'); + $this->newLine(); + + $this->sourceFile = false; + } + } + + /** + * Get the destination class path. + * + * @param string $name + * @return string + */ + protected function getPath($name) + { + if ($this->sourceViewNamespace) { + $themePath = Str::contains($this->sourceViewNamespace, '::') ? + Str::before($this->sourceViewNamespace, '::') : + Str::beforeLast($this->sourceViewNamespace, '.'); + + $themePath = Str::replace('.', '/', $themePath); + + $path = 'views/vendor/'.$themePath.'/'.$this->viewNamespace.'/'.$name.'.blade.php'; + + return resource_path($path); + } + + $path = 'views/vendor/backpack/crud/'.$this->viewNamespace.'/'.$name.'.blade.php'; + + return resource_path($path); + } +} diff --git a/src/Console/stubs/chip.stub b/src/Console/stubs/chip.stub new file mode 100644 index 0000000..78a832e --- /dev/null +++ b/src/Console/stubs/chip.stub @@ -0,0 +1,29 @@ +@php + // ---------------------------------- + // Create any variables you need here + // ---------------------------------- + // If you're using this chip as a column inside ListOperation, or as a widget inside ShowOperation, + // you will most likely have the $entry variable. +@endphp + +@include('crud::chips.general', [ + 'heading' => [ + 'content' => $entry->name, + 'href' => backpack_url('example/'.$entry->id.'/show'), + ], + 'image' => [ + 'content' => asset($entry->avatar->url), + ], + 'details' => [ + [ + 'icon' => 'la la-shopping-cart', + 'content' => $entry->invoices->count(). ' purchases', + 'title' => 'Number of purchases: '.$entry->invoices->count(), + ], + [ + 'icon' => 'la la-calendar', + 'content' => $entry->created_at->format('F j, Y'), + 'title' => 'Sign up date: '.$last_purchase, + ] + ] +]) diff --git a/src/GeneratorsServiceProvider.php b/src/GeneratorsServiceProvider.php index 833daf5..1b891b9 100644 --- a/src/GeneratorsServiceProvider.php +++ b/src/GeneratorsServiceProvider.php @@ -18,6 +18,7 @@ use Backpack\Generators\Console\Commands\RequestBackpackCommand; use Backpack\Generators\Console\Commands\ViewBackpackCommand; use Backpack\Generators\Console\Commands\Views\ButtonBackpackCommand; +use Backpack\Generators\Console\Commands\Views\ChipBackpackCommand; use Backpack\Generators\Console\Commands\Views\ColumnBackpackCommand; use Backpack\Generators\Console\Commands\Views\FieldBackpackCommand; use Backpack\Generators\Console\Commands\Views\FilterBackpackCommand; @@ -29,6 +30,7 @@ class GeneratorsServiceProvider extends ServiceProvider protected $commands = [ BuildBackpackCommand::class, ButtonBackpackCommand::class, + ChipBackpackCommand::class, ColumnBackpackCommand::class, ConfigBackpackCommand::class, CrudModelBackpackCommand::class, From 6f7cf04d01a87f08639b116d43adbb26fdde1d37 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 25 Jun 2025 10:57:55 +0000 Subject: [PATCH 4/5] Apply fixes from StyleCI --- src/Console/Commands/Views/ChipBackpackCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Console/Commands/Views/ChipBackpackCommand.php b/src/Console/Commands/Views/ChipBackpackCommand.php index 23afb5d..16d673b 100644 --- a/src/Console/Commands/Views/ChipBackpackCommand.php +++ b/src/Console/Commands/Views/ChipBackpackCommand.php @@ -103,6 +103,7 @@ private function setupChipSourceFile() if (view()->exists($viewPath)) { $this->sourceFile = view($viewPath)->getPath(); $this->sourceViewNamespace = $viewPath; + return; } } @@ -111,6 +112,7 @@ private function setupChipSourceFile() $vendorChipPath = base_path("vendor/backpack/crud/src/resources/views/crud/chips/{$from}.blade.php"); if (file_exists($vendorChipPath)) { $this->sourceFile = $vendorChipPath; + // Don't set sourceViewNamespace so it uses the default path logic return; } @@ -118,11 +120,13 @@ private function setupChipSourceFile() // Third, try full or relative file paths (parent behavior) if (file_exists($from)) { $this->sourceFile = realpath($from); + return; } // remove the first slash to make absolute paths relative in unix systems elseif (file_exists(substr($from, 1))) { $this->sourceFile = realpath(substr($from, 1)); + return; } From e8cf29a3420d228815da8a073a92da54734ea4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20T=C4=83b=C4=83citu?= Date: Wed, 19 Nov 2025 08:30:53 +0200 Subject: [PATCH 5/5] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f8c37e3..9bc16f8 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } ], "require": { - "backpack/crud": "^7.0.0-alpha" + "backpack/crud": "^7.0" }, "autoload": { "psr-4": {