Skip to content

Generator Overview

The Generator allows users to define and configure models along with their fields for a Laravel application. Users can customize the model name, fields, relationships, and other attributes that will be used to generate the backend API, database, and frontend CMS.

UI Preview

Generator

Model Configuration

FieldDescriptionDefaultExampleValidation
Model NameDefines the name of the modelCategoryRequired
Model Name DisplayDisplay name in menu barCategory SidebarRequired

Options

FieldDescriptionDefaultExampleValidation
TimestampsAutomatically adds created_at and updated_at columns to the table.CheckedOptional
Soft DeletesAdds support for soft deletion (adds a deleted_at column).CheckedOptional
User SignatureAdds created_by and updated_by columns to track who created/updated records.UnCheckedOptional
APi OnlyOnly generate the APIUnCheckedOptional
Ignore MigrateSkips running database migrations.UnCheckedOptional
Only MigrateOnly generate migration and Model.UnCheckedOptional
Test CasesGenerates test cases for the model and related services.CheckedOptional

Fields Configuration

FieldDescriptionDefaultExampleValidation
Field NameThe name of the field in the database.nameRequired
Field Name DisplayDisplay name for the field in the user interface.NameRequired
Field OptionSetting unique, indexing, and adding comments.Optional
Database TypeThe type of the field in the database (e.g., Increments, VARCHAR, LONGTEXT).VARCHAR(255)VARCHAR(255)Required
Default ValueThe default value for this field if none is provided.NULLRequired
Search/Sort/Show/LayoutOn/Off search, sort, and show in the table. The column layout can be adjusted to a value between 1 and 24.Optional
DeleteOption to delete the field from the configuration.

🔧 Field Option

OptionDescriptionExample
UniqueEnsures the field value is unique across all records in the database.Enabled for email field to ensure unique emails.
IndexCreates an index on the field to optimize database query performance.Enabled for status field to improve search speed.
CommentAdds a comment for the field in the database, useful for documentation or clarification purposes.Indicates if the category is active or inactive.

UI Preview

Generator Option

📦 Database Type

🗄️ Database

Database TypeDisplay NameSearchSortShow
incrementsIncrements🚫
integerINTEGER
unsignedIntegerUNSIGNED INTEGER
tinyIntegerTINYINT
unsignedTinyIntegerUNSIGNED TINYINT
smallIntegerSMALLINT
unsignedSmallIntegerUNSIGNED SMALLINT
mediumIntegerMEDIUMINT
unsignedMediumIntegerUNSIGNED MEDIUMINT
bigIntegerBIGINT
unsignedBigIntegerUNSIGNED BIGINT
floatFLOAT
doubleDOUBLE
decimalDECIMAL
booleanBOOLEAN
dateDATE
dateTimeDATETIME
timestampTIMESTAMP
timeTIME
yearYEAR
charCHAR
stringVARCHAR
tinyTextTINYTEXT
mediumTextMEDIUMTEXT
textTEXT
longTextLONGTEXT
enumENUM
jsonJSON🚫🚫
jsonbJSONB🚫🚫
Relationship Types
hasOnehasOne
hasManyhasMany

📝 Form

Each Database Type will feature a distinct UI, with our focus centered on utilizing the Element Plus components.

Database TypeUI Preview
INTEGER, UNSIGNED INTEGER, TINYINT, UNSIGNED TINYINT, SMALLINT, UNSIGNED SMALLINT, MEDIUMINT, UNSIGNED MEDIUMINT, BIGINT, UNSIGNED BIGINT, FLOAT, DOUBLE, DECIMAL
BOOLEAN
DATEdate
DATETIME, TIMESTAMPinteger
TIMEtime
YEARyear
CHAR, VARCHARvarchar
TINYTEXT, MEDIUMTEXT, TEXTtext
LONGTEXTlongtext
ENUMenum
JSON, JSONBjson

Relationships

There are two ways to create relationships in our system:

Example:

Post → belongs to → Category

Category → has many → Post

📝 Generate Form

This way just only for hasMany or belongsTo

UI Preview

Relationships Form

📝 Relationship Form

This way for all relationship such as: hasOne, hasMany, belongsToMany

UI Preview

Relationships Form

Relationships Form

🔄 Many To Many

Many to many will generate pivot table. By default, the pivot table is CategoryPost ({Model1} + {Model2}).

UI Preview

Relationships Many To Many

php
<?php

return new class extends Migration
{
    public function up()
    {
        Schema::create('category_post', function (Blueprint $table) {
            $table->foreignId('category_id')->index();
            $table->foreignId('post_id')->index();
            $table->primary(['category_id', 'post_id']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('category_post');
    }
};

DBML beta

The DBML Interface

LaraJS provides a clean, user-friendly interface for importing DBML content:

DBML ModalDBML Interface

The interface provides:

  • A large text area for pasting DBML content
  • A reference example to help users understand the syntax
  • A link to the official DBML documentation
  • A parse button to process the DBML and generate model fields

Complete Type Mapping Reference

The LaraJS DBML parser supports a comprehensive range of database types, mapping them automatically to their corresponding LaraJS database types:

DBML TypeLaraJS Database Type
int, integerINTEGER
tinyintTINYINT
smallintSMALLINT
mediumintMEDIUMINT
bigintBIGINT
floatFLOAT
doubleDOUBLE
decimalDECIMAL
boolean, boolBOOLEAN
dateDATE
datetimeDATETIME
timestampTIMESTAMP
timeTIME
yearYEAR
charCHAR
varchar, stringVARCHAR
textTEXT
tinytextTINYTEXT
mediumtextMEDIUMTEXT
longtextLONGTEXT
jsonJSON
jsonbJSONB
enumENUM
unsigned int, unsignedintUNSIGNED INTEGER
unsigned integer, unsignedintegerUNSIGNED INTEGER
unsigned tinyint, unsignedtinyintUNSIGNED TINYINT
unsigned smallint, unsignedsmallintUNSIGNED SMALLINT
unsigned mediumint, unsignedmediumintUNSIGNED MEDIUMINT
unsigned bigint , unsignedbigintUNSIGNED BIGINT

Example DBML Syntax:

txt
Table users {
  id integer [pk]
  user_info_id bigint [ref: - user_infos.id]
  username varchar(50) [unique, not null]
  email varchar [unique, not null]
  password varchar [not null]
  profile_image varchar
  bio text
  role enum('admin', 'user', 'editor') [default: 'user']
  is_active boolean [default: true]
  created_at timestamp
  updated_at timestamp
}

Field Attributes and Their Mappings

The DBML parser also handles various field attributes and maps them to appropriate LaraJS configurations:

DBML AttributeLaraJS Equivalent
pkIdentifies the primary key field
not nullSets default value to "None" instead of "NULL"
uniqueEnables the "Unique" field option
indexEnables the "Index" field option
note: 'text'Sets a comment in the field options
comment: 'text'Sets a comment in the field options
default: valueSets default value to "As define" with the value
ref: > table.columnCreates a "hasMany" relationship to the table
ref: < table.columnCreates a "hasOne" relationship with the table
incrementMaps to autoincrement field type

Relationship Detection

The DBML parser can detect relationships from reference syntax:

  • [ref: > users.id] detects a hasMany relationship
  • [ref: < comments.post_id] detects a hasOne relationship

Best Practices for DBML Import

For the best results when working with DBML in LaraJS:

  1. Field Naming: Use snake_case for field names in DBML to maintain consistency with Laravel conventions
  2. Relationship Definition: Explicitly define relationships using the ref: syntax to ensure proper relationship detection
  3. Comprehensive Attributes: Include all necessary attributes like unique constraints, defaults, and comments for complete model generation
  4. Review After Import: Always review the generated fields after import to ensure they meet your requirements
  5. Incremental Approach: For complex schemas, consider importing tables one at a time rather than all at once
  6. DBML First Design: Consider using DBML as your initial database design tool before implementation to streamline the development process

Handling Complex Data Types

The DBML parser intelligently handles more complex data types:

  • Enum Types: When using enum('value1', 'value2'), LaraJS automatically creates an ENUM field with the provided values
  • Length Specification: For types like varchar(255), the parser correctly sets the length_varchar property
  • Decimal Precision: For decimal, LaraJS sets up the appropriate decimal configuration

Troubleshooting Common Issues

IssueSolution
Relationships not detectedEnsure you're using the proper ref: syntax with direction
Field types not mappingCheck the type mapping table and use a supported DBML type
Default values not applyingUse the format [default: value] with appropriate quotes
Unique constraints not appliedMake sure to include [unique] in the field attributes
Model name not generatedCheck the table name format - it should be Table name {...}