Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Fields Ai Laravel Package

broqit/fields-ai

Laravel Nova field that brings AI to your admin forms, letting you generate and refine text content directly in fields. Adds configurable prompts/actions to speed up writing, editing, and content creation inside Nova resources.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require broqit/fields-ai
    

    Publish the config file (if available):

    php artisan vendor:publish --provider="Broqit\FieldsAI\FieldsAIServiceProvider"
    
  2. Basic Usage Inject the FieldsAI facade into your controller or service:

    use Broqit\FieldsAI\Facades\FieldsAI;
    
    // Generate a field description
    $description = FieldsAI::describeField('user', 'email');
    
  3. First Use Case Use in a form builder to auto-generate field labels, placeholders, or validation rules:

    $label = FieldsAI::generateLabel('user', 'email'); // "User Email Address"
    $placeholder = FieldsAI::generatePlaceholder('user', 'email'); // "example@domain.com"
    

Implementation Patterns

Common Workflows

  1. Dynamic Form Field Generation

    // In a FormRequest or FormService
    public function rules()
    {
        $rules = [];
        $fields = ['name', 'email', 'bio'];
    
        foreach ($fields as $field) {
            $rules[$field] = FieldsAI::inferValidation($field);
        }
    
        return $rules;
    }
    
  2. Localization Support

    // Generate labels in multiple languages
    $labels = [
        'en' => FieldsAI::generateLabel('product', 'price', 'en'),
        'es' => FieldsAI::generateLabel('product', 'price', 'es'),
    ];
    
  3. Integration with Laravel Blade

    @foreach($formFields as $field)
        <div>
            <label>{{ FieldsAI::generateLabel($model, $field) }}</label>
            <input type="text" name="{{ $field }}">
            <span class="help-text">{{ FieldsAI::generateHelpText($model, $field) }}</span>
        </div>
    @endforeach
    
  4. API Response Enhancement

    // Auto-generate API response metadata
    $response = [
        'data' => $user,
        'fields' => [
            'email' => FieldsAI::describeField('user', 'email'),
            'created_at' => FieldsAI::describeField('user', 'created_at'),
        ],
    ];
    
  5. Model Casting

    // Auto-generate attribute descriptions for API docs
    class User extends Model
    {
        public function getAttributeDescriptions()
        {
            return collect($this->attributes)
                ->mapWithKeys(fn ($value, $key) => [
                    $key => FieldsAI::describeField('user', $key)
                ]);
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Rate Limiting

    • The package may hit API rate limits if used excessively in bulk operations (e.g., generating labels for 100+ fields at once).
    • Solution: Cache responses aggressively:
      $label = Cache::remember("fields_ai_{$model}_{$field}", now()->addHours(1), function() use ($model, $field) {
          return FieldsAI::generateLabel($model, $field);
      });
      
  2. Model/Field Mismatches

    • The AI may generate incorrect descriptions if the model or field names are ambiguous (e.g., user vs. users).
    • Solution: Use fully qualified names:
      FieldsAI::describeField('App\Models\User', 'email'); // Explicit namespace
      
  3. Contextual Overrides

    • AI-generated descriptions may not account for custom business logic (e.g., a password field that’s actually a "PIN").
    • Solution: Extend the package via service providers:
      // app/Providers/FieldsAIServiceProvider.php
      public function boot()
      {
          FieldsAI::extend('user', 'pin', function ($model, $field) {
              return "4-digit security code (e.g., 1234)";
          });
      }
      
  4. Configuration Quirks

    • The fields-ai config may not be published by default. Check for:
      config('fields-ai.api_key'); // Ensure this is set
      config('fields-ai.cache_enabled'); // Toggle caching
      

Debugging Tips

  1. Enable Verbose Logging Add to config/fields-ai.php:

    'debug' => env('FIELDS_AI_DEBUG', false),
    

    Then check storage/logs/laravel.log for AI response details.

  2. Mocking for Testing Use the FieldsAI facade’s mocking methods:

    FieldsAI::shouldReceive('generateLabel')
            ->once()
            ->with('user', 'email')
            ->andReturn('Test Email');
    
    $this->assertEquals('Test Email', FieldsAI::generateLabel('user', 'email'));
    
  3. Fallback Logic Provide defaults for when the AI fails:

    $label = FieldsAI::generateLabel('user', 'email', [
        'fallback' => ucfirst(str_replace('_', ' ', $field)),
    ]);
    

Extension Points

  1. Custom Prompts Override the default AI prompts via config:

    'prompts' => [
        'label' => 'Generate a user-friendly label for the {field} field in a {model} resource.',
        'validation' => 'Suggest Laravel validation rules for the {field} field in a {model}.',
    ],
    
  2. Field Type Hints Pass additional context to improve accuracy:

    FieldsAI::describeField('order', 'status', [
        'type' => 'enum',
        'options' => ['pending', 'shipped', 'delivered'],
    ]);
    
  3. Batch Processing Use the batch() method for efficiency:

    $descriptions = FieldsAI::batch(['user' => ['email', 'password']]);
    // Returns: ['user.email' => "...", 'user.password' => "..."]
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor