PHP code example of dottwatson / laravel-model-meta

1. Go to this page and download the library: Download dottwatson/laravel-model-meta 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/ */

    

dottwatson / laravel-model-meta example snippets



return [
    ...
    // This is the identifier for the meta type
    'int' => [
        // This is the casting that will be applied on the query. %s will be replaced with the meta name
        'database_casting' => 'CAST(%s.value AS UNSIGNED)', 
        // This is the model casting, according with laravale casting
        'model_casting' => 'int'
    ],
    ...
]


return [
        ...
    \My\Namespace\ModelName::class => [
        'mymeta' => ['type'=>\Dottwatson\Meta::JSON,...],
    ],
    ...
    \My\Namespace\ModelName::class => [
        'mymeta' => ['type'=>'json',...], // the type is defined in model-meta-type
        ...
    ]
]



namespace App\Models;

...
use Dottwatson\ModelMeta\ModelMeta;

class MyModel extends Model
{
    use ModelMeta;
    ...
    protected $tableMeta = 'mymodel_meta';

   ...

}




namespace App\Models;

...
use Dottwatson\ModelMeta\ModelMeta;

class MyModel extends Model
{
    use ModelMeta;
    ...
    protected $tableMeta = 'mymodel_meta';

   ...
   
   protected static function metaAttributes()
   {
       return [
        'mymeta' => ['type'=>'json',...], // the type is defined in model-meta-type
       ];
   }
}




namespace App\Models;

...
use Dottwatson\ModelMeta\ModelMeta;

class MyModel extends Model
{
   ...
 
    public static function metaReference()
    {
        return 'my_column';
    }
    
    ...

}

php artisan vendor:publish --tag=model-meta-config