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.
Installation
composer require-dev fibers/helper
require-dev as the package is designed for development-time introspection.First Facade Import
use Fibers\Helper\Facades\ModelHelper;
Basic Usage
$modelInfo = ModelHelper::fromClass('App\Models\User')->collect('attributes');
User model.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)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']);
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']);
Service Provider Analysis
use Fibers\Helper\Facades\ProviderHelper;
// List all bindings in a provider
$bindings = ProviderHelper::fromClass('App\Providers\AppServiceProvider')
->collect('bindings');
Integration with Testing
// Dynamic test data generation
$testData = ModelHelper::fromClass('App\Models\User')
->collect('attributes')
->mapWithKeys(fn($col) => [$col => fake()->$col]);
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'));
Performance Overhead
collect('relationships') queries the DB).app/Helpers/ or use ModelHelper::cache() (if available).Outdated Laravel Compatibility
class ExtendedModelHelper extends \Fibers\Helper\Helpers\ModelHelper {
public function collectEnums(string $modelClass) { ... }
}
Facade vs. Direct Usage
$helper = app(\Fibers\Helper\Helpers\ModelHelper::class);
Namespace Collisions
Fibers\Helper alongside other Fibers packages, ensure consistent aliasing in config/app.php:
'aliases' => [
'ModelHelper' => \Fibers\Helper\Facades\ModelHelper::class,
],
Relationship Collection Quirks
collect('relationships') may miss lazy-loaded or dynamic relationships.ModelHelper::with() to preload:
ModelHelper::fromClass('App\Models\Order')
->with(['user', 'items'])
->collect('relationships');
Inspect Raw Data
Use dd() to debug helper outputs:
dd(ModelHelper::fromClass('App\Models\User')->collect('attributes', 'relationships'));
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');
}
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');
}
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();
}
}
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.
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());
}
}
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'),
];
}
});
Testing Helpers Mock helpers in tests using partial mocks:
$helper = $this->partialMock(ModelHelper::class, ['collect']);
$helper->method('collect')->willReturn(['id', 'name']);
How can I help you explore Laravel packages today?