PHP code example of storephp / bundler

1. Go to this page and download the library: Download storephp/bundler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

storephp / bundler example snippets

 title=storephp.php


use StorePHP\Bundler\BundleRegistrar;

BundleRegistrar::register(BundleRegistrar::MODULE, '<vendor>_<module>', __DIR__);



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' => 'mbnail',
            'model' => 'thumbnail_path',
            'rules' => '



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');
    }
}



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',
        ]);
    }
};



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;
    }
}

Route::prefix('catalog')->group(function () {
    // Set routes
});
 title=etc/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');
    }
};
 title=etc/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
        ]);
    }
};
 title=etc/sidebar.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',
        );
    }
};

text
.
└── <vendor>/<module>/
    └── etc/
    │   ├── forms
    │   ├── grids
    │   ├── routes/
    │   │   └── admin.php
    │   ├── acl.php
    │   ├── module.php
    │   └── sidebar.php
    └── storephp.php