Laravel AI Schema Documentation

Learn how to write a valid schema for the Laravel AI Code Generator.

This schema format allows the AI to automatically generate:

  • Laravel migrations
  • Models
  • Controllers
  • API routes
  • Web routes
  • Relationships
  • Validation rules
  • Resources

1. Table Structure

Every table must follow this structure:


table:table_name

primary:id

columns

timestamps

softDeletes

relationships

2. Table Names

Use lowercase plural names with snake_case.

Correct

users

blog_posts

order_items

Wrong

Users

BlogPosts

OrderItems

3. Primary Key

Every table should contain:

primary:id

4. Column Syntax

Columns use this format:

column_name=type|validation1|validation2

Example:

name=string|required|max:255

email=string|required|email|unique

5. Supported Column Types

Type Example
string name=string
text content=text
integer age=integer
boolean is_active=boolean
decimal price=decimal:10,2
date publish_date=date
datetime published_at=datetime
json settings=json
enum status=enum:draft,published

6. Validation Rules

Validation rules are separated using |

title=string|required|max:255

7. Foreign Keys

user_id=foreign|table:users|onDelete:cascade

Foreign keys automatically generate database constraints and relationships.

8. Relationships

Relationships use this format:

relationship:type:model
relationship:hasMany:posts
relationship:belongsTo:user
relationship:belongsToMany:tags

11. Complete Example


table:users
primary:id
name=string|required|max:255
email=string|required|unique
password=string|required
timestamps

relationship:hasMany:posts
relationship:hasMany:comments


table:posts
primary:id
user_id=foreign|table:users|onDelete:cascade
title=string|required|max:255
slug=string|required|unique
content=text|required
status=enum:draft,published|default:draft
timestamps
softDeletes



relationship:belongsTo:user
relationship:hasMany:comments
relationship:belongsToMany:tags


table:comments
primary:id
post_id=foreign|table:posts|onDelete:cascade
user_id=foreign|table:users|onDelete:cascade
comment=text|required
timestamps
relationship:belongsTo:post
relationship:belongsTo:user


table:tags
primary:id
name=string|required|unique
timestamps
relationship:belongsToMany:posts


pivot:post_tag
post_id=foreign|table:posts|onDelete:cascade
tag_id=foreign|table:tags|onDelete:cascade

12. Common Mistakes

Wrong

table:User
user_id=foreign
relationship:user:posts

Correct

table:users
user_id=foreign|table:users|onDelete:cascade
relationship:hasMany:posts

13. Best Practices

  • Always use primary:id
  • Add timestamps to all tables
  • Use softDeletes for important tables
  • Use plural table names
  • Use snake_case naming
  • Always define foreign keys properly
  • Keep schema clean and readable

Loved by Developers ❤️

★★★★★

Hirfix AI reduced my backend development time from weeks to just 2 hours. The code quality is incredible!

★★★★★

The schema to Laravel feature is a game changer. Upload ERD and get full backend structure instantly.

★★★★★

Perfect for rapid development and MVPs. Clean code, good documentation and excellent support.

🚀

Ready to build your next Laravel project?

Join thousands of developers who are building faster with Hirfix AI.