PHP code example of macromindonline / eloquent-model-generator

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

    

macromindonline / eloquent-model-generator example snippets


'providers' => [
    // ...
    Krlove\EloquentModelGenerator\Provider\GeneratorServiceProvider::class,
];



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



return [
    'namespace'       => 'Some\\Other\\Namespace',
    'base_class_name' => 'Some\\Other\\ClassName',
    'output_path'     => '/full/path/to/output/directory',
    'no_timestamps'   => true,
    'date_format'     => 'U',
    'connection'      => 'other-connection',
];



namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * @property int $id
 * @property int $role_id
 * @property mixed $username
 * @property mixed $email
 * @property Role $role
 * @property Article[] $articles
 * @property Comment[] $comments
 */
class User extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user';

    /**
     * @var array
     */
    protected $fillable = ['role_id', 'username', 'email'];

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

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function articles()
    {
        return $this->hasMany('Article');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function comments()
    {
        return $this->hasMany('Comment');
    }
}

php artisan krlove:generate:model User

php artisan krlove:generate:model User --table-name=user

php artisan krlove:generate:model User --base-class-name=Some\\Other\\Base\\Model

php artisan krlove:generate:model User --config=<your-base-dir>/config/eloquent_model_generator.php

php artisan krlove:generate:model User  --table-name=user