Laravel 13.x BuildSpec β†’ Code (LoRA Adapter)

LoRA adapter for Qwen2.5-Coder-7B-Instruct that converts structured BuildSpec JSON objects into complete Laravel 13.x PHP files.

Base model: Qwen/Qwen2.5-Coder-7B-Instruct Quantized base for MLX: mlx-community/Qwen2.5-Coder-7B-Instruct-4bit Training dataset: fchis/laravel-buildspec-training

What is BuildSpec?

Instead of natural language, you describe each Laravel artifact precisely:

{
  "artifact": "model",
  "class": "Subscriber",
  "namespace": "App\\Models",
  "table": "subscribers",
  "has_factory": true,
  "soft_deletes": false,
  "fillable": ["email", "name", "status", "subscribed_at"],
  "casts": {"subscribed_at": "datetime"},
  "relationships": [],
  "scopes": [{"name": "active", "column": "status", "value": "active"}]
}

The model outputs the complete PHP file β€” no markdown, no explanations.

Why BuildSpec?

Approach Error type Fix method
Natural language Model invents things not asked for Runtime debugging
BuildSpec JSON Wrong field names, missing spec fields Spec compiler validates before generation

Spec errors are compiler-catchable before generation runs.

Usage (MLX)

from mlx_lm import load, generate

model, tokenizer = load(
    "mlx-community/Qwen2.5-Coder-7B-Instruct-4bit",
    adapter_path="fchis/Laravel-13x-Qwen2.5-Coder-7B-Instruct-LoRA-Spec"
)

SYSTEM = """You are a Laravel 13.x PHP code generator. Input is a BuildSpec JSON object. Output is the complete PHP file.

Rules:
- Output ONLY the PHP file. No markdown fences. No explanation.
- artifact=model: ALWAYS add use HasFactory when has_factory=true. ONLY add relationship methods listed in relationships[].
- artifact=controller: ALWAYS import App\\Http\\Controllers\\Controller and Illuminate\\Http\\Request. destroy() returns response()->noContent(). store() returns response()->json($resource, 201).
- artifact=resource: ALWAYS import Illuminate\\Http\\Resources\\Json\\JsonResource. For EVERY entry in loaded_relations[] that has a "resource" key, add the use import.
- artifact=form_request: If conditional_rules present, expand using $this->isMethod('POST') ternary or spread. For POST-only rules use spread: `...$this->isMethod('POST') ? ['rule'] : []`. authorize() returns true."""

spec = {
    "artifact": "model",
    "class": "Post",
    "namespace": "App\\Models",
    "table": "posts",
    "has_factory": True,
    "fillable": ["title", "body", "user_id"],
    "relationships": [
        {"type": "BelongsTo", "model": "User", "method": "author", "foreign_key": "user_id"}
    ]
}

import json
msgs = [
    {"role": "system", "content": SYSTEM},
    {"role": "user", "content": json.dumps(spec, indent=2)},
]
prompt = tokenizer.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
prompt += "<?php\n"
result = generate(model, tokenizer, prompt=prompt, max_tokens=1000, verbose=False)
print("<?php\n" + result)

Supported Artifacts

Artifact Description
model Eloquent model with fillable, casts, relationships, scopes
controller API resource controller (inline or form_request validation)
form_request FormRequest with conditional_rules support
resource API Resource with loaded_relations
pest_test Pest feature tests for CRUD endpoints
migration Database migration (create table)

Full Pipeline

See laravel-ai-gen:

# NL β†’ specs β†’ compile β†’ generate PHP files
python3 pipeline_spec.py "Create a REST API for managing blog posts with tags"

Training Details

  • Base model: Qwen2.5-Coder-7B-Instruct (4-bit quantized via MLX)
  • Method: LoRA (rank 8, --num-layers 8)
  • Framework: mlx-lm
  • Hardware: Apple M2 Pro 16GB
  • Training data: 49 examples (45 train / 4 valid)
  • Iterations: 175 total (100 base + 25 v2 + 25 v3 + 25 v4)
  • Final val_loss: 0.031

Results

Tested on a 3-app benchmark (Subscriber API, Book Library, Event Management):

Metric Score
PHP syntax valid 26/26 (100%)
Eval perfect (0 bugs) 26/26 (100%)
Pest tests pass 20/20 (100%)
after:now conditional rule Fixed (v4)

Comparison: Spec vs Prompt approach

Config Pest pass Manual fixes Error type
Prompt (adapters_v9) 52/58 5 Semantic hallucinations
Spec (this model) 20/20 4 Spec quality issues

Spec fixes are deterministic and compiler-catchable. Prompt fixes require runtime debugging.

Citation

@misc{laravel-buildspec-2026,
  author    = {Florinel Chis},
  title     = {Laravel 13.x BuildSpec to Code LoRA Adapter},
  year      = {2026},
  publisher = {Hugging Face},
  url       = {https://huggingface.co/fchis/Laravel-13x-Qwen2.5-Coder-7B-Instruct-LoRA-Spec}
}
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for fchis/Laravel-13x-Qwen2.5-Coder-7B-Instruct-LoRA-Spec

Base model

Qwen/Qwen2.5-7B
Adapter
(576)
this model

Spaces using fchis/Laravel-13x-Qwen2.5-Coder-7B-Instruct-LoRA-Spec 3