PHP code example of rayvenues / eloquent-model-generator

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

    

rayvenues / eloquent-model-generator example snippets




return [
    'namespace' => 'App',
    'base_class_name' => \Illuminate\Database\Eloquent\Model::class,
    'output_path' => null,
    'no_timestamps' => null,
    'date_format' => null,
    'connection' => null,
    'no_backup' => null,
    'db_types' => null,
];

return [
    // ...
    'db_types' => [
        '<TYPE>' => 'string',
    ],
];



namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * @property integer $id
 * @property integer $role_id
 * @property string $username
 * @property string $email
 * @property Role $role
 */
class User extends Model
{
    /**
     * @var array
     */
    protected $fillable = ['role_id', 'username', 'email'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function role(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo('App\Models\Role');
    }
}

class PerPageProcessor implements ProcessorInterface
{
    public function process(EloquentModel $model, Config $config): void
    {
        $propertyModel = new PropertyModel('perPage', 'protected', 20);
        $dockBlockModel = new DocBlockModel('The number of models to return for pagination.', '@var int');
        $propertyModel->setDocBlock($dockBlockModel);
        $model->addProperty($propertyModel);
        
        $propertyModel = new PropertyModel('guarded', 'protected', []);
        $dockBlockModel = new DocBlockModel('¡Tengo miedo!.', '@var array');
        $propertyModel->setDocBlock($dockBlockModel);
        $model->addProperty($propertyModel);

    }

    public function getPriority(): int
    {
        return 8;
    }
}

public function register()
{
    $this->app->tag([PerPageProcessor::class], [GeneratorServiceProvider::PROCESSOR_TAG]);
}

...
/**
 * The number of models to return for pagination.
 * 
 * @var int
 */
protected $perPage = 20;

/**
 * ¡Tengo miedo!.
 * 
 * @var array
 */
protected $guarded = [];
...
BASH
php artisan ray:generate:model User
BASH
php artisan ray:generate:model User --table-name=user
BASH
php artisan ray:generate:model User --base-class-name=Custom\\Base\\Model
BASH
php artisan ray:generate:model User --no-backup
BASH
php artisan ray:generate:model User --no-timestamps
BASH
php artisan ray:generate:model User --connection='mysql'
BASH
php artisan vendor:publish --provider="Ray\EloquentModelGenerator\Provider\GeneratorServiceProvider"
BASH
php artisan ray:generate:model User
BASH
php artisan ray:generate:models --skip-table=users --skip-table=roles
BASH
php artisan ray:generate:models --skip-table="users,roles"