1. Go to this page and download the library: Download swattech/crud 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/ */
namespace App\Generators;
use SwatTech\Crud\Generators\ModelGenerator as BaseModelGenerator;
class CustomModelGenerator extends BaseModelGenerator
{
public function getStub(string $filename = ""): string
{
return resource_path('stubs/custom-model.stub');
}
public function buildClass(string $table, array $schema, array $relationships): string
{
// Custom implementation
$content = parent::buildClass($table, $schema, $relationships);
// Add your customizations
$content = str_replace(
'// Custom traits',
'use App\\Traits\\CustomTrait;',
$content
);
return $content;
}
}
// In AppServiceProvider or custom service provider
public function register()
{
$this->app->bind(
\SwatTech\Crud\Generators\ModelGenerator::class,
\App\Generators\CustomModelGenerator::class
);
}