PHP code example of simplecms / dynamic_unit
1. Go to this page and download the library: Download simplecms/dynamic_unit 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/ */
simplecms / dynamic_unit example snippets
// config/app.php
SimpleCMS\DynamicUnit\DynamicUnitServiceProvider::class,
use Illuminate\Database\Eloquent\Model;
use SimpleCMS\DynamicUnit\Traits\DynamicAttributeTrait;
class Product extends Model
{
use DynamicAttributeTrait;
}
$array = ['red', 'blue'];
$products = Product::query()
->withAttributeCodes($array)
->get();
use SimpleCMS\DynamicUnit\Facades\DynamicUnit;
DynamicUnit::createUnit([
'name' => 'Color',
'code' => 'color',
'items' => [
['name' => 'Red', 'code' => 'red'],
['name' => 'Blue', 'code' => 'blue'],
],
]);
$all = DynamicUnit::getAll();
$unit = DynamicUnit::findByCode('color');
$items = DynamicUnit::findListByCode('color');
$attr = DynamicUnit::findAttributeByCode('color', 'red');
DynamicUnit::updateUnit(1, [
'name' => 'Color',
'code' => 'color',
'items' => [
['id' => 10, 'name' => 'Red', 'code' => 'red'],
['name' => 'Green', 'code' => 'green'],
],
]);
DynamicUnit::deleteAttribute(10);
DynamicUnit::deleteUnit(1);
use SimpleCMS\DynamicUnit\Facades\DynamicUnit;
DynamicUnit::getAll();
DynamicUnit::findByCode(string $code);
DynamicUnit::findListByCode(string $code);
DynamicUnit::findAttributeByCode(string $code, string $attributeCode);
DynamicUnit::createUnit(array $data);
DynamicUnit::updateUnit(int $id, array $data);
DynamicUnit::deleteUnit(int $id);
DynamicUnit::createAttribute(array $data);
DynamicUnit::updateAttribute(int $id, array $data);
DynamicUnit::deleteAttribute(int $id);
use SimpleService;
$service = app(SimpleService::class);
$service->queryAttribute(['red', 'blue']);
bash
composer migrate
bash
php artisan migrate:fresh
bash
php artisan optimize:clear