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

Helper Laravel Package

fibers/helper

Developer-focused Laravel helper toolkit used by Fibers packages. Provides assorted utilities to inspect and modify app parts (e.g., models), collecting details like attributes and relationships. Install via composer and access helpers through facades like ModelHelper.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require-dev fibers/helper
    
    • Use require-dev as the package is designed for development-time introspection.
  2. First Facade Import

    use Fibers\Helper\Facades\ModelHelper;
    
  3. Basic Usage

    $modelInfo = ModelHelper::fromClass('App\Models\User')->collect('attributes');
    
    • Outputs an array of column names for the User model.
  4. Key Files to Review

    • config/fibers-helper.php (if present, though minimal)
    • vendor/fibers/helper/src/Facades/ (facade definitions)
    • vendor/fibers/helper/src/Helpers/ (core helper logic)

Implementation Patterns

Common Workflows

  1. Model Introspection

    // Collect all attributes + relationships
    $modelData = ModelHelper::fromClass('App\Models\Post')
        ->collect('attributes', 'relationships');
    
    // Filter by specific columns
    $columns = ModelHelper::fromClass('App\Models\Post')
        ->collect('attributes', ['id', 'title']);
    
  2. Controller/Route Inspection

    use Fibers\Helper\Facades\ControllerHelper;
    
    // Get all routes for a controller
    $routes = ControllerHelper::fromClass('App\Http\Controllers\AdminController')
        ->collect('routes');
    
    // Get route actions with middleware
    $actions = ControllerHelper::fromClass('App\Http\Controllers\AdminController')
        ->collect('actions', ['middleware']);
    
  3. Service Provider Analysis

    use Fibers\Helper\Facades\ProviderHelper;
    
    // List all bindings in a provider
    $bindings = ProviderHelper::fromClass('App\Providers\AppServiceProvider')
        ->collect('bindings');
    
  4. Integration with Testing

    // Dynamic test data generation
    $testData = ModelHelper::fromClass('App\Models\User')
        ->collect('attributes')
        ->mapWithKeys(fn($col) => [$col => fake()->$col]);
    

Integration Tips

  • Leverage in bootstrap/app.php Use for runtime application analysis (e.g., debugging misconfigurations):

    $modelSchema = ModelHelper::fromClass('App\Models\Order')->collect('attributes');
    
  • Dynamic Form Generation

    $fields = ModelHelper::fromClass('App\Models\Product')
        ->collect('attributes')
        ->map(fn($attr) => view('components.form.input', ['name' => $attr]));
    
  • API Documentation Tools Combine with ControllerHelper to auto-generate OpenAPI specs:

    $endpoints = ControllerHelper::scan('App\Http\Controllers')
        ->collect('routes')
        ->map(fn($route) => [
            'path' => $route['uri'],
            'methods' => $route['methods'],
        ]);
    
  • Migration Validation

    $expectedColumns = ModelHelper::fromClass('App\Models\Post')->collect('attributes');
    $actualColumns = DB::select("PRAGMA table_info(posts)");
    assert($expectedColumns === array_column($actualColumns, 'name'));
    

Gotchas and Tips

Pitfalls

  1. Performance Overhead

    • Avoid using in production or high-frequency loops. Helpers perform runtime reflection (e.g., collect('relationships') queries the DB).
    • Mitigation: Cache results in app/Helpers/ or use ModelHelper::cache() (if available).
  2. Outdated Laravel Compatibility

    • Last release (2019) may lack support for Laravel 10+ features (e.g., enums, new query builder methods).
    • Workaround: Extend helpers via traits or create a wrapper:
      class ExtendedModelHelper extends \Fibers\Helper\Helpers\ModelHelper {
          public function collectEnums(string $modelClass) { ... }
      }
      
  3. Facade vs. Direct Usage

    • Facades add slight overhead. For heavy usage, inject the helper class directly:
      $helper = app(\Fibers\Helper\Helpers\ModelHelper::class);
      
  4. Namespace Collisions

    • If using Fibers\Helper alongside other Fibers packages, ensure consistent aliasing in config/app.php:
      'aliases' => [
          'ModelHelper' => \Fibers\Helper\Facades\ModelHelper::class,
      ],
      
  5. Relationship Collection Quirks

    • collect('relationships') may miss lazy-loaded or dynamic relationships.
    • Tip: Combine with ModelHelper::with() to preload:
      ModelHelper::fromClass('App\Models\Order')
          ->with(['user', 'items'])
          ->collect('relationships');
      

Debugging Tips

  1. Inspect Raw Data Use dd() to debug helper outputs:

    dd(ModelHelper::fromClass('App\Models\User')->collect('attributes', 'relationships'));
    
  2. Check for Deprecated Methods Wrap calls in a try-catch for graceful degradation:

    try {
        $data = ModelHelper::fromClass('App\Models\Post')->collect('old_method');
    } catch (\BadMethodCallException $e) {
        $data = ModelHelper::fromClass('App\Models\Post')->collect('attributes');
    }
    
  3. Verify Model Existence Helpers may throw exceptions for non-existent models. Validate first:

    if (!class_exists('App\Models\InvalidModel')) {
        throw new \RuntimeException('Model not found');
    }
    

Extension Points

  1. Custom Helpers Extend the base Helper class to add domain-specific logic:

    namespace App\Helpers;
    
    use Fibers\Helper\Helpers\BaseHelper;
    
    class MyCustomHelper extends BaseHelper {
        public function collectCustomData(string $modelClass) {
            return $this->getModel($modelClass)->getCustomAttribute();
        }
    }
    
  2. Override Facades Publish and modify the facade bindings:

    php artisan vendor:publish --tag=fibers-helper-facades
    

    Then update config/fibers-helper.php to point to your extended helpers.

  3. Add New Collection Types Implement the Collectable interface to support custom data sources:

    class CacheHelper extends BaseHelper implements Collectable {
        public function collect(string $type, $options = null) {
            return Cache::get($this->getTarget());
        }
    }
    
  4. Integration with Laravel Debugbar Add helper data to the debug toolbar:

    Debugbar::addCollector(new class extends \Debugbar\DataCollector\DataCollector {
        public function collect() {
            return [
                'model_attributes' => ModelHelper::fromClass('App\Models\User')->collect('attributes'),
            ];
        }
    });
    
  5. Testing Helpers Mock helpers in tests using partial mocks:

    $helper = $this->partialMock(ModelHelper::class, ['collect']);
    $helper->method('collect')->willReturn(['id', 'name']);
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui