PHP code example of hogen / laravel-generator

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

    

hogen / laravel-generator example snippets


'providers' => [
    ···
    App\Console\Commands\Generator\GeneratorServiceProvider::class
];

protected $types = [
    'model', 'request', 'resource', 'service', 'controller', 'test', 'migration'
];

protected $pathFormat = [
    'model'      => ['inBaseDir' => false, 'prefix' => ''],
    'service'    => ['inBaseDir' => false, 'prefix' => ''],
    'test'       => ['inBaseDir' => false, 'prefix' => true],
    'request'    => ['inBaseDir' => true, 'prefix' => true],
    'resource'   => ['inBaseDir' => true, 'prefix' => true],
    'controller' => ['inBaseDir' => true, 'prefix' => true],
    'migration'  => ['inBaseDir' => false, 'prefix' => ''],
];

protected $createFilter = false;
protected $baseFilterHelperPath = "Models\Traits\Filter";

/**
 * 手动配置
 * resource文件中不需要添加到 $fillable 的字段
 *
 * @var string[]
 */
protected $resourceNoFillableFields = [
    'update_time',
    'updated_time',
    'delete_time',
    'deleted_time',
];

/**
 * 手动配置
 * model文件中不需要添加到 $fillable 的字段
 *
 * @var string[]
 */

protected $modelNoFillableFields = [
    'id',
    'create_time',
    'created_time',
    'update_time',
    'updated_time',
    'delete_time',
    'deleted_time',
];



namespace DummyNamespace;

use NamespacedDummyModel;
use NamespacedDummyRequest;
use NamespacedDummyResource;
use NamespacedDummyService;
use BaseNamespaceResource\EmptyResource;
use BaseNamespaceController\Controller;

class DummyClass extends Controller
{
    public function index(DummyRequest $request){
        $validated = $request->validated();
        $dummyModels = DummyModel::query()
            ->filter($validated)
            ->orderByDesc('id')
            ->paginate();
        return DummyResource::collection($dummyModels);
    }
    ···
}