Skip to content

request-generator

Agent for generating Laravel Form Request validation classes

From plugin
f5-framework
24104 skills104 agents69 commands
Install
$ npx -y skills add Fujigo-Software/f5-framework-claude --agent claude-code

How it fires

How this agent gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.

Context preview

The summary Claude sees to decide when to auto-load this agent.

Agent for generating Laravel Form Request validation classes

Agent definition

request-generator.md
name: laravel-request-generator
description: Agent for generating Laravel Form Request validation classes
applies_to: laravel
category: agent

Laravel Request Generator Agent

Purpose

Generate production-ready Laravel Form Request classes with validation rules, authorization, and custom messages.

Input Requirements

required:
  - entity_name: string          # e.g., "Product"
  - action: string               # "create" or "update"

optional:
  - fields: object               # Field definitions with rules
  - authorization: boolean       # Include authorization (default: true)
  - custom_messages: boolean     # Include custom messages (default: true)
  - custom_attributes: boolean   # Include custom attributes (default: true)
  - prepare_validation: boolean  # Include prepareForValidation (default: true)

Generation Process

Step 1: Analyze Model and Schema

// Get validation requirements from model and migration
$model = app("App\\Models\\{$entityName}");
$table = $model->getTable();
$columns = Schema::getColumnListing($table);
$fillable = $model->getFillable();

Step 2: Generate Create Request

<?php
// app/Http/Requests/{{Entity}}/Create{{Entity}}Request.php
namespace App\Http\Requests\{{Entity}};

use App\Enums\{{Entity}}Status;
use App\Models\{{Entity}};
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Enum;

class Create{{Entity}}Request extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return $this->user()->can('create', {{Entity}}::class);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
     */
    public function rules(): array
    {
        return [
            // Required string fields
            'name' => [
                'required',
                'string',
                'min:3',
                'max:255',
                Rule::unique('{{entities}}', 'name'),
            ],

            // Optional text fields
            'description' => [
                'nullable',
                'string',
                'max:5000',
            ],

            // Numeric fields
            'price' => [
                'required',
                'numeric',
                'min:0',
                'max:999999.99',
            ],
            'compare_price' => [
                'nullable',
                'numeric',
                'min:0',
                'gt:price',
            ],

            // Foreign key references
            'category_id' => [
                'required',
                'uuid',
                Rule::exists('categories', 'id')->whereNull('deleted_at'),
            ],

            // Enum fields
            'status' => [
                'sometimes',
                new Enum({{Entity}}Status::class),
            ],

            // Boolean fields
            'is_featured' => [
                'sometimes',
                'boolean',
            ],

            // Array fields
            'tags' => [
                'nullable',
                'array',
                'max:10',
            ],
            'tags.*' => [
                'string',
                'max:50',
                Rule::exists('tags', 'id'),
            ],

            // JSON/Object fields
            'metadata' => [
                'nullable',
                'array',
            ],
            'metadata.key' => [
                'sometimes',
                'string',
                'max:100',
            ],

            // File uploads
            'image' => [
                'nullable',
                'image',
                'mimes:jpeg,png,webp',
                'max:2048', // 2MB
                'dimensions:min_width=100,min_height=100,max_width=4000,max_height=4000',
            ],

            // Date fields
            'published_at' => [
                'nullable',
                'date',
                'after_or_equal:today',
            ],
        ];
    }

    /**
     * Get custom attributes for validator errors.
     *
     * @return array<string, string>
     */
    public function attributes(): array
    {
        return [
            'category_id' => 'category',
            'compare_price' => 'compare price',
            'is_featured' => 'featured status',
            'published_at' => 'publication date',
        ];
    }

    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'name.required' => 'The {{entity}} name is required.',
            'name.unique' => 'A {{entity}} with this name already exists.',
            'price.required' => 'Please specify a price for the {{entity}}.',
            'price.min' => 'The price cannot be negative.',
            'compare_price.gt' => 'The compare price must be greater than the regular price.',
            'category_id.exists' => 'The selected category does not exist.',
            'tags.max' => 'You can only add up to 10 tags.',
            'image.max' => 'The image must not exceed 2MB.',
        ];
    }

    /**
     * Prepare the data for validation.
     */
    protected function prepareForValidation(): void
    {
        // Trim string fields
        if ($this->has('name')) {
            $this->merge([
                'name' => trim($this->name),
            ]);
        }

        // Normalize boolean fields
        if ($this->has('is_featured')) {
            $this->merge([
                'is_featured' => filter_var($this->is_featured, FILTER_VALIDATE_BOOLEAN),
            ]);
        }

        // Set defaults
        if (!$this->has('status')) {
            $this->merge([
                'status' => {{Entity}}Status::Draft->value,
            ])
Read more
Ships withf5-framework

AI-Powered Development Framework for Claude Code

Get the whole plugin, auto-invoked
Stats
24
Stars
0
Views
8
Forks
Quiet
Maintenance
Python
Language
MIT
License
6mo ago
Last commit
6mo ago
Created

Repo: Fujigo-Software/f5-framework-claude