storephp / bundler
There is no license information available for the latest version (v1.0.0-beta.2) of this package.
This is StorePHP's framework for building bundles
v1.0.0-beta.2
2023-09-13 16:03 UTC
This package is auto-updated.
Last update: 2024-11-13 18:38:37 UTC
README
StorePHP Bundler
This is StorePHP's framework for building bundles
Module structure
.
└── <vendor>/<module>/
└── etc/
│ ├── forms
│ ├── grids
│ ├── routes/
│ │ └── admin.php
│ ├── acl.php
│ ├── module.php
│ └── sidebar.php
└── storephp.php
create new module
Create a storephp.php
file in the module
directory in the vendor
directory
<?php use StorePHP\Bundler\BundleRegistrar; BundleRegistrar::register(BundleRegistrar::MODULE, '<vendor>_<module>', __DIR__);
Forms
build new form
<?php use StorePHP\Bundler\Contracts\Form\FormHasFields; use StorePHP\Bundler\Contracts\Form\FormHasTabs; use StorePHP\Bundler\Lib\Form\Fields; use StorePHP\Bundler\Lib\Form\Tabs; return new class implements FormHasTabs, FormHasFields { public function tabs(Tabs $tabs) { $tabs->addTab('default', 'Product info'); $tabs->addTab('priceing', 'Product price'); $tabs->addTab('images', 'Images'); } public function fields(Fields $form) { $form->addField('text', [ 'label' => 'Product name', 'model' => 'name', 'rules' => 'required', 'order' => 10, ]); $form->addField('text', [ 'label' => 'Product price', 'model' => 'price', 'rules' => 'required', 'order' => 10, 'hint' => 'Add product price', ], 'priceing'); $form->addField('text', [ 'label' => 'Product discount price', 'model' => 'discount_price', 'rules' => 'nullable', 'order' => 20, 'hint' => 'Add product discount price', ], 'priceing'); $form->addField('file', [ 'label' => 'Product thumbnail', 'model' => 'thumbnail_path', 'rules' => 'required', 'order' => 10, 'hint' => 'Update product', ], 'images'); } };
Runder this form
<?php namespace StorePHP\Catalog\Http\Livewire\Products; use Livewire\WithFileUploads; use Store\Support\Facades\Product; use StorePHP\Bundler\Abstracts\FromAbstract; use StorePHP\Dashboard\Views\Layouts\DashboardLayout; class ProductCreate extends FromAbstract { use WithFileUploads; protected $pretitle = 'Catalog'; protected $title = 'Create new product'; public $formId = 'storephp_catalog_products_form'; public function layout() { return DashboardLayout::class; } public function submit() { $validateData = $this->validate(); $product = Product::create([ 'sku' => $validateData['sku'], ]); foreach ($this->models(['sku', 'thumbnail_path']) as $model) { $product->{$model} = $validateData[$model]; } if ($this->thumbnail_path) { $product->thumbnail_path = $this->thumbnail_path->store('photos'); } $product->save(); return $this->pushAlert('success', 'The product has been created'); } }
Grids
build new grid
<?php use StorePHP\Bundler\Contracts\Grid\GridHasButtons; use StorePHP\Bundler\Contracts\Grid\GridHasCTA; use StorePHP\Bundler\Contracts\Grid\GridHasTable; use StorePHP\Bundler\Lib\Grid\Bottom; use StorePHP\Bundler\Lib\Grid\CTA; use StorePHP\Bundler\Lib\Grid\Table; return new class implements GridHasTable, GridHasButtons, GridHasCTA { public function model() { return config('store.catalog.products.model'); } public function createBottom(Bottom $bottom) { $bottom->setBottom('Create new product', 'store.dashboard.catalog.products.create'); } public function table(Table $table) { $table->setColumn('#', 'id') ->setColumn('Name', 'name') ->setColumn('Slug', 'slug'); } public function CTA(CTA $CTA) { $CTA->setCall('Edit', [ 'type' => 'route', 'color' => 'info', 'route' => 'store.dashboard.catalog.products.update', ]); } };
Runder this grid
<?php namespace StorePHP\Catalog\Http\Livewire\Products; use StorePHP\Bundler\Abstracts\GridAbstract; use StorePHP\Dashboard\Views\Layouts\DashboardLayout; class ProductsIndex extends GridAbstract { public $gridId = 'storephp_catalog_products_index'; protected $pretitle = 'Catalog'; protected $title = 'Products listing'; public function layout() { return DashboardLayout::class; } }
Create routes
In the routes folder, you can create an admin.php file.
Route::prefix('catalog')->group(function () { // Set routes });
Create ACL
<?php use StorePHP\Bundler\Lib\ACL; use StorePHP\Bundler\Contracts\ACL\HasPermissions; return new class implements HasPermissions { public function permissions(ACL $acl) { $acl->permission('Catalog', 'catalog'); } };
module
<?php use StorePHP\Catalog\Providers\StoreCatalogServiceProvider; use StorePHP\Bundler\Lib\Module; use StorePHP\Bundler\Contracts\Module\iModule; return new class implements iModule { public function info(Module $module) { $module->name('Catalog'); $module->provoiders([ StoreCatalogServiceProvider::class ]); } };
Sidebar builder
<?php use StorePHP\Bundler\Contracts\Sidebar\HasLinks; use StorePHP\Bundler\Contracts\Sidebar\HasMenu; use StorePHP\Bundler\Lib\Sidebar\Menu; use StorePHP\Bundler\Lib\Sidebar\Links; return new class implements HasMenu, HasLinks { public function menu(Menu $menu) { $menu->info( icon: 'clipboard-list', label: 'Catalog', order: 20, ); } public function links(Links $links) { $links->link( icon: 'category', label: 'Categories', href: 'store.dashboard.catalog.categories.index', ); $links->link( icon: 'packages', label: 'Products', href: 'store.dashboard.catalog.products.index', ); } };