PHP code example of augustpermana / hypervel-meta-generator
1. Go to this page and download the library: Download augustpermana/hypervel-meta-generator 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/ */
augustpermana / hypervel-meta-generator example snippets
namespace App\Models;
use App\Models\Model;
use AugustPermana\HypervelMetaGenerator\Traits\HasMetadata;
class Product extends Model
{
use HasMetadata;
// ... model code lainnya
}
$product = Product::find(1);
$product->setMeta('warranty_period', 24); // Auto-detected as integer
$product->setMeta('is_featured', true); // Auto-detected as boolean
$product->setMeta('specifications', [ // Auto-detected as json
'color' => 'black',
'weight' => '1.5kg'
]);
$warrantyPeriod = $product->getMeta('warranty_period'); // Returns: 24 (as integer)
$isFeatured = $product->getMeta('is_featured'); // Returns: true (as boolean)
$specs = $product->getMeta('specifications'); // Returns: array
// Dengan default value
$discount = $product->getMeta('discount', 0); // Returns: 0 jika tidak ada
// Hapus semua metadata yang ada dan ganti dengan yang baru
$product->syncMeta([
'brand' => 'Apple',
'model' => 'iPhone 15',
'price' => 999.99
]);
if ($product->hasMeta('warranty_period')) {
// Metadata exists
}
$product->removeMeta('old_field');
// Cari semua produk yang featured
$featuredProducts = Product::whereHasMeta('is_featured', '1')->get();
// Cari semua produk yang punya metadata 'warranty_period'
$productsWithWarranty = Product::whereHasMeta('warranty_period')->get();