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

Jsonapi Documentation Laravel Package

bornfight/jsonapi-documentation

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer:

composer require vendor/package-name

The package provides string manipulation utilities (e.g., pluralization, singularization, camelCase conversion) using Doctrine Inflector (replacing Symfony Inflector in v0.1.2). For quick testing, use the facade:

use PackageName\Facades\Inflector;

Inflector::pluralize('tax'); // Returns "taxes" (fixed from "tacies")
Inflector::singularize('productDetails'); // Returns "productDetail" (fixed from "productDetailss")

Implementation Patterns

Core Use Cases

  1. Model Naming Conventions Dynamically generate table names or model names from class names:

    $modelName = Inflector::classify('user_profile'); // "UserProfile"
    $tableName = Inflector::tableize($modelName);     // "user_profiles"
    
  2. API/Route Labeling Auto-generate human-readable labels for API responses or route names:

    $label = Inflector::humanize('is_active'); // "Is Active"
    
  3. Form/Validation Messages Localize error messages dynamically:

    $message = Inflector::titleize('invalid ' . Inflector::pluralize('credit_card')); // "Invalid Credit Cards"
    

Integration Tips

  • Service Providers: Bind the Inflector facade in AppServiceProvider for global access.

  • Blade Directives: Create custom directives for template-friendly usage:

    Blade::directive('plural', function ($expression) {
        return "<?php echo \\PackageName\\Inflector::pluralize({$expression}); ?>";
    });
    

    Usage: @plural('tax') → "taxes".

  • Eloquent Events: Use inflection in model observers for consistent naming:

    public function created(User $user) {
        $user->update(['slug' => Inflector::slugify($user->name)]);
    }
    

Gotchas and Tips

Breaking Changes (v0.1.2)

  • Symfony Inflector Deprecation: All methods now use Doctrine Inflector under the hood. Test edge cases like:
    • Inflector::pluralize('child') → "children" (correct, vs. Symfony’s "childs").
    • Inflector::singularize('people') → "person" (correct, vs. Symfony’s "people").
  • Cache Invalidation: Clear cached views/config if you relied on old inflection behavior.

Debugging Tips

  1. Edge Cases: For unexpected outputs, check the Doctrine Inflector docs or test manually:

    dd(Inflector::getRules()); // Inspect active rules.
    
  2. Custom Rules: Extend the inflector by publishing the config:

    php artisan vendor:publish --provider="PackageName\ServiceProvider"
    

    Then modify config/inflector.php to add custom rules (e.g., for acronyms like "NASA" → "NASAs").

  3. Performance: Doctrine Inflector is faster than Symfony’s for large-scale operations (e.g., batch processing).

Pro Tips

  • Localization: Combine with Laravel’s Str::of() for locale-aware inflection:
    Str::of('tax')->plural(); // Uses Doctrine Inflector.
    
  • Testing: Use Inflector::testMode() to mock rules in PHPUnit:
    Inflector::testMode(true);
    Inflector::addRule('special_case', 'regex', 'replacement');
    
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle