PHP code example of augustpermana / laravel-meta-generator

1. Go to this page and download the library: Download augustpermana/laravel-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 / laravel-meta-generator example snippets


'providers' => [
    // Other Service Providers

    August\MetaGenerator\ServiceProvider::class,
],

     

     namespace App\Models;

     use Illuminate\Database\Eloquent\Model;
     use AugustPermana\MetaGenerator\Traits\HasMetadata;

     class Book extends Model
     {
         use HasMetadata;
     }
     

  $value = $book->getMeta('author');
  

  $book->setMeta('publisher', 'Acme Publishing');
  

  $book->setManyMeta([
      'isbn' => '1234567890',
      'pages' => 350,
      'published_at' => '2025-02-22'
  ]);
  

  $book->syncMeta([
      'genre' => 'Fiction',
      'language' => 'English'
  ]);
  

  // Retrieve models with any value for the "author" metadata
  $models = Model::whereHasMeta('author')->get();

  // Retrieve models with a specific "author" value
  $models = Model::whereHasMeta('author', 'John Doe')->get();
  
bash
   php artisan make:metadata --model=Book
   
bash
php artisan make:metadata --model=ModelName
bash
php artisan metadata:clean-orphaned --model=ModelName