[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. No extra comments.
- Implement EXACTLY what the spec says. Do not add fields, relationships, or methods not in the spec.
- artifact=model: ALWAYS add use HasFactory when has_factory=true. ONLY add relationship methods listed in relationships[]. Import every relationship return type (BelongsTo etc).
- artifact=controller: ALWAYS import App\Http\Controllers\Controller and Illuminate\Http\Request. destroy() returns response()->noContent(). store() returns response()->json($resource, 201). If validation_mode=inline use $request->validate([...]) in store() and update(). If validation_mode=form_request import and use the FormRequest class.
- artifact=resource: ALWAYS import Illuminate\Http\Resources\Json\JsonResource. For EVERY entry in loaded_relations[] that has a "resource" key, add `use App\Http\Resources\{ResourceClass};` at the top — even if it is in the same namespace. Never use a Resource class without importing it.
- artifact=form_request: rules() returns exact rules from spec. If conditional_rules present, expand each field using $this->isMethod('POST') ternary or spread. For POST-only rules use spread: `...$this->isMethod('POST') ? ['rule'] : []`. authorize() returns true. When unique_ignore_route_param is set (non-null), replace any 'unique:table,col' string rule with Rule::unique('table', 'col')->ignore($this->route('param')). Import use Illuminate\Validation\Rule; at the top.
- artifact=controller: When the model has FK fields in fillable (e.g. author_id, category_id), ALWAYS include them in $request->validated() passed to Model::create(). NEVER exclude FK fields or set them separately after create().

[User]
{
  "laravel_version": "13.x",
  "artifact": "pest_test",
  "class": "Event",
  "namespace": "Tests\\Feature",
  "model": "App\\Models\\Event",
  "endpoints": [
    {
      "method": "GET",
      "path": "/api/events",
      "action": "index"
    },
    {
      "method": "POST",
      "path": "/api/events",
      "action": "store"
    },
    {
      "method": "GET",
      "path": "/api/events/{id}",
      "action": "show"
    },
    {
      "method": "PUT",
      "path": "/api/events/{id}",
      "action": "update"
    },
    {
      "method": "DELETE",
      "path": "/api/events/{id}",
      "action": "destroy"
    }
  ],
  "required_on_create": [
    "title",
    "event_date",
    "venue_id"
  ],
  "optional_on_update": [
    "venue_id"
  ]
}

[Assistant]
<?php
use App\Models\Event;
use App\Models\Venue;
use App\Models\Speaker;

test('GET /api/events returns paginated list', function () {
    Event::factory()->count(3)->create();
    $this->getJson('/api/events')
        ->assertOk()
        ->assertJsonCount(3, 'data');
});

test('POST /api/events creates an event', function () {
    $venue = Venue::factory()->create();
    $this->postJson('/api/events', [
        'title'      => 'Test Event',
        'event_date' => now()->addDays(10)->toDateString(),
        'venue_id'   => $venue->id,
    ])->assertCreated()
      ->assertJsonPath('title', 'Test Event');
});

test('POST /api/events requires venue_id', function () {
    $this->postJson('/api/events', [
        'title'      => 'Test Event',
        'event_date' => now()->addDays(10)->toDateString(),
    ])->assertUnprocessable()
      ->assertJsonValidationErrors(['venue_id']);
});

test('PUT /api/events/:id venue_id is optional', function () {
    $event = Event::factory()->create();
    $this->putJson("/api/events/{$event->id}", [
        'title' => 'Updated Event',
    ])->assertOk()
      ->assertJsonPath('title', 'Updated Event');
});

test('DELETE /api/events/:id deletes the event', function () {
    $event = Event::factory()->create();
    $this->deleteJson("/api/events/{$event->id}")
        ->assertNoContent();
    $this->assertDatabaseMissing('events', ['id' => $event->id]);
});


[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. No extra comments.
- Implement EXACTLY what the spec says. Do not add fields, relationships, or methods not in the spec.
- artifact=model: ALWAYS add use HasFactory when has_factory=true. ONLY add relationship methods listed in relationships[]. Import every relationship return type (BelongsTo etc).
- artifact=controller: ALWAYS import App\Http\Controllers\Controller and Illuminate\Http\Request. destroy() returns response()->noContent(). store() returns response()->json($resource, 201). If validation_mode=inline use $request->validate([...]) in store() and update(). If validation_mode=form_request import and use the FormRequest class.
- artifact=resource: ALWAYS import Illuminate\Http\Resources\Json\JsonResource. For EVERY entry in loaded_relations[] that has a "resource" key, add `use App\Http\Resources\{ResourceClass};` at the top — even if it is in the same namespace. Never use a Resource class without importing it.
- artifact=form_request: rules() returns exact rules from spec. If conditional_rules present, expand each field using $this->isMethod('POST') ternary or spread. For POST-only rules use spread: `...$this->isMethod('POST') ? ['rule'] : []`. authorize() returns true. When unique_ignore_route_param is set (non-null), replace any 'unique:table,col' string rule with Rule::unique('table', 'col')->ignore($this->route('param')). Import use Illuminate\Validation\Rule; at the top.
- artifact=controller: When the model has FK fields in fillable (e.g. author_id, category_id), ALWAYS include them in $request->validated() passed to Model::create(). NEVER exclude FK fields or set them separately after create().

[User]
{
  "laravel_version": "13.x",
  "artifact": "resource",
  "class": "BookResource",
  "namespace": "App\\Http\\Resources",
  "fields": [
    {
      "key": "id",
      "source": "id"
    },
    {
      "key": "title",
      "source": "title"
    },
    {
      "key": "isbn",
      "source": "isbn"
    },
    {
      "key": "description",
      "source": "description",
      "modifier": "whenNotNull"
    },
    {
      "key": "published_year",
      "source": "published_year",
      "modifier": "whenNotNull"
    },
    {
      "key": "created_at",
      "source": "created_at"
    },
    {
      "key": "updated_at",
      "source": "updated_at"
    }
  ],
  "loaded_relations": [
    {
      "key": "author",
      "resource": "AuthorResource",
      "type": "make"
    }
  ]
}

[Assistant]
<?php
namespace App\Http\Resources;

use App\Http\Resources\AuthorResource;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class BookResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'             => $this->id,
            'title'          => $this->title,
            'isbn'           => $this->isbn,
            'description'    => $this->whenNotNull($this->description),
            'published_year' => $this->whenNotNull($this->published_year),
            'author'         => AuthorResource::make($this->whenLoaded('author')),
            'created_at'     => $this->created_at,
            'updated_at'     => $this->updated_at,
        ];
    }
}


[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. No extra comments.
- Implement EXACTLY what the spec says. Do not add fields, relationships, or methods not in the spec.
- artifact=model: ALWAYS add use HasFactory when has_factory=true. ONLY add relationship methods listed in relationships[]. Import every relationship return type (BelongsTo etc).
- artifact=controller: ALWAYS import App\Http\Controllers\Controller and Illuminate\Http\Request. destroy() returns response()->noContent(). store() returns response()->json($resource, 201). If validation_mode=inline use $request->validate([...]) in store() and update(). If validation_mode=form_request import and use the FormRequest class.
- artifact=resource: ALWAYS import Illuminate\Http\Resources\Json\JsonResource. For EVERY entry in loaded_relations[] that has a "resource" key, add `use App\Http\Resources\{ResourceClass};` at the top — even if it is in the same namespace. Never use a Resource class without importing it.
- artifact=form_request: rules() returns exact rules from spec. If conditional_rules present, expand each field using $this->isMethod('POST') ternary or spread. For POST-only rules use spread: `...$this->isMethod('POST') ? ['rule'] : []`. authorize() returns true. When unique_ignore_route_param is set (non-null), replace any 'unique:table,col' string rule with Rule::unique('table', 'col')->ignore($this->route('param')). Import use Illuminate\Validation\Rule; at the top.
- artifact=controller: When the model has FK fields in fillable (e.g. author_id, category_id), ALWAYS include them in $request->validated() passed to Model::create(). NEVER exclude FK fields or set them separately after create().

[User]
{
  "laravel_version": "13.x",
  "artifact": "resource",
  "class": "PostResource",
  "namespace": "App\\Http\\Resources",
  "fields": [
    {
      "key": "id",
      "source": "id"
    },
    {
      "key": "title",
      "source": "title"
    },
    {
      "key": "body",
      "source": "body"
    },
    {
      "key": "status",
      "source": "status"
    },
    {
      "key": "created_at",
      "source": "created_at"
    }
  ],
  "loaded_relations": [
    {
      "key": "author",
      "resource": "AuthorResource",
      "type": "make"
    },
    {
      "key": "tags",
      "resource": "TagResource",
      "type": "collection"
    }
  ]
}

[Assistant]
<?php
namespace App\Http\Resources;

use App\Http\Resources\AuthorResource;
use App\Http\Resources\TagResource;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class PostResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'         => $this->id,
            'title'      => $this->title,
            'body'       => $this->body,
            'status'     => $this->status,
            'author'     => AuthorResource::make($this->whenLoaded('author')),
            'tags'       => TagResource::collection($this->whenLoaded('tags')),
            'created_at' => $this->created_at,
        ];
    }
}


[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. No extra comments.
- Implement EXACTLY what the spec says. Do not add fields, relationships, or methods not in the spec.
- artifact=model: ALWAYS add use HasFactory when has_factory=true. ONLY add relationship methods listed in relationships[]. Import every relationship return type (BelongsTo etc).
- artifact=controller: ALWAYS import App\Http\Controllers\Controller and Illuminate\Http\Request. destroy() returns response()->noContent(). store() returns response()->json($resource, 201). If validation_mode=inline use $request->validate([...]) in store() and update(). If validation_mode=form_request import and use the FormRequest class.
- artifact=resource: ALWAYS import Illuminate\Http\Resources\Json\JsonResource. For EVERY entry in loaded_relations[] that has a "resource" key, add `use App\Http\Resources\{ResourceClass};` at the top — even if it is in the same namespace. Never use a Resource class without importing it.
- artifact=form_request: rules() returns exact rules from spec. If conditional_rules present, expand each field using $this->isMethod('POST') ternary or spread. For POST-only rules use spread: `...$this->isMethod('POST') ? ['rule'] : []`. authorize() returns true. When unique_ignore_route_param is set (non-null), replace any 'unique:table,col' string rule with Rule::unique('table', 'col')->ignore($this->route('param')). Import use Illuminate\Validation\Rule; at the top.
- artifact=controller: When the model has FK fields in fillable (e.g. author_id, category_id), ALWAYS include them in $request->validated() passed to Model::create(). NEVER exclude FK fields or set them separately after create().

[User]
{
  "laravel_version": "13.x",
  "artifact": "form_request",
  "class": "Order",
  "namespace": "App\\Http\\Requests",
  "rules": {
    "customer_id": [],
    "status": [
      "required",
      "string",
      "in:pending,processing,shipped,delivered,cancelled"
    ],
    "shipping_address": [],
    "notes": [
      "nullable",
      "string"
    ],
    "items": [],
    "items.*.product_id": [
      "integer",
      "exists:products,id"
    ],
    "items.*.quantity": [
      "integer",
      "min:1"
    ]
  },
  "conditional_rules": {
    "customer_id": {
      "POST": [
        "required",
        "integer",
        "exists:customers,id"
      ],
      "PUT": [
        "sometimes",
        "integer",
        "exists:customers,id"
      ]
    },
    "shipping_address": {
      "POST": [
        "required",
        "string"
      ],
      "PUT": [
        "sometimes",
        "string"
      ]
    },
    "items": {
      "POST": [
        "required",
        "array",
        "min:1"
      ],
      "PUT": [
        "sometimes",
        "array"
      ]
    }
  }
}

[Assistant]
<?php
namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreOrderRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'customer_id'        => [$this->isMethod('POST') ? 'required' : 'sometimes', 'integer', 'exists:customers,id'],
            'status'             => ['required', 'string', 'in:pending,processing,shipped,delivered,cancelled'],
            'shipping_address'   => [$this->isMethod('POST') ? 'required' : 'sometimes', 'string'],
            'notes'              => ['nullable', 'string'],
            'items'              => [$this->isMethod('POST') ? 'required' : 'sometimes', 'array', ...$this->isMethod('POST') ? ['min:1'] : []],
            'items.*.product_id' => ['integer', 'exists:products,id'],
            'items.*.quantity'   => ['integer', 'min:1'],
        ];
    }
}


[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. No extra comments.
- Implement EXACTLY what the spec says. Do not add fields, relationships, or methods not in the spec.
- artifact=model: ALWAYS add use HasFactory when has_factory=true. ONLY add relationship methods listed in relationships[]. Import every relationship return type (BelongsTo etc).
- artifact=controller: ALWAYS import App\Http\Controllers\Controller and Illuminate\Http\Request. destroy() returns response()->noContent(). store() returns response()->json($resource, 201). If validation_mode=inline use $request->validate([...]) in store() and update(). If validation_mode=form_request import and use the FormRequest class.
- artifact=resource: ALWAYS import Illuminate\Http\Resources\Json\JsonResource. For EVERY entry in loaded_relations[] that has a "resource" key, add `use App\Http\Resources\{ResourceClass};` at the top — even if it is in the same namespace. Never use a Resource class without importing it.
- artifact=form_request: rules() returns exact rules from spec. If conditional_rules present, expand each field using $this->isMethod('POST') ternary or spread. For POST-only rules use spread: `...$this->isMethod('POST') ? ['rule'] : []`. authorize() returns true. When unique_ignore_route_param is set (non-null), replace any 'unique:table,col' string rule with Rule::unique('table', 'col')->ignore($this->route('param')). Import use Illuminate\Validation\Rule; at the top.
- artifact=controller: When the model has FK fields in fillable (e.g. author_id, category_id), ALWAYS include them in $request->validated() passed to Model::create(). NEVER exclude FK fields or set them separately after create().

[User]
{
  "laravel_version": "13.x",
  "artifact": "form_request",
  "class": "StoreEventRequest",
  "namespace": "App\\Http\\Requests",
  "authorize": true,
  "rules": {
    "title": [
      "required",
      "string",
      "max:255"
    ],
    "description": [
      "nullable",
      "string"
    ],
    "venue_id": [
      "required_on_post",
      "integer",
      "exists:venues,id"
    ],
    "event_date": [
      "required",
      "date",
      "after_now_on_post"
    ],
    "status": [
      "nullable",
      "string",
      "in:draft,published,cancelled"
    ],
    "speaker_ids": [
      "nullable",
      "array"
    ],
    "speaker_ids.*": [
      "integer",
      "exists:speakers,id"
    ]
  },
  "unique_ignore_route_param": null
}

[Assistant]
<?php
namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreEventRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'title'         => ['required', 'string', 'max:255'],
            'description'   => ['nullable', 'string'],
            'venue_id'      => [$this->isMethod('POST') ? 'required' : 'sometimes', 'integer', 'exists:venues,id'],
            'event_date'    => ['required', 'date', $this->isMethod('POST') ? 'after:now' : 'sometimes'],
            'status'        => ['nullable', 'string', 'in:draft,published,cancelled'],
            'speaker_ids'   => ['nullable', 'array'],
            'speaker_ids.*' => ['integer', 'exists:speakers,id'],
        ];
    }
}