PHP code example of zero-to-prod / db-model

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

    

zero-to-prod / db-model example snippets


'namespace' => 'App\\Sources\\Db',
'path' => app_path('Sources/Db'),

// app/Sources/Db/App/Users.php
namespace App\Sources\Db\App;

use ZeroToProd\DbModel\Column;
use ZeroToProd\DbModel\ColumnType;
use ZeroToProd\DbModel\HasColumnAttribute;
use ZeroToProd\DbModel\Table;

/**
 * @method string type()
 * @method string|null comment()
 * @method int|null length()
 * @method bool|null nullable()
 * @method bool|null unique()
 * @method bool|null primary_key()
 * @method bool|null auto_increment()
 */
#[Table(
    schema: App::class,
    attributes: [
        Table::name => 'users',
        Table::comment => 'The users table',
        Table::collate => 'utf8mb4_unicode_ci',
    ])]
enum Users: string
{
    use HasColumnAttribute;

    #[Column([
        Column::name => self::email,
        Column::comment => 'The users email',
        Column::type => ColumnType::varchar->value,
        Column::length => 255,
        Column::nullable => false,
        Column::unique => true,
    ])]
    case email = 'email';
}

Users::email->value;      // 'email'
Users::email->rules();    // [' 255
Users::email->unique();   // true
Users::email->comment();  // 'The users email'

public function rules(): array
{
    return [
        'email' => [...Users::email->rules(), 'email', 'unique:users'],
        'password' => [...Users::password->rules(), 'confirmed'],
    ];
}

// config/db-model.php
'trait' => App\Sources\Db\HasColumn::class,

Users::created_at->cast();   // 'immutable_datetime'
Users::created_at->rules();  // ['nullable', 'date'] — still from the package

// config/db-model.php
'implements' => App\Sources\Db\Authority::class,
'implements' => [App\Sources\Db\Authority::class, App\Sources\Db\Sortable::class],

enum Users: string implements Authority, Sortable
{
    use HasColumn;

'mcp' => [
    'enabled' => true,
    'handle' => 'db-model',
],
bash
php artisan db-model:install
bash
php artisan vendor:publish --tag=db-model-config
bash
php artisan db-model:generate   # the enums now `use HasColumn`
bash
php artisan db-model:generate
bash
php artisan db-model:check
bash
php artisan db-model:check --schema=Reporting --connection=mysql --database=reporting
php artisan db-model:generate --schema=Reporting --database=reporting --path=/tmp/reporting
bash
claude mcp add db-model -- php artisan mcp:start db-model