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

Rest Entity Manager Laravel Package

alberto-leon-crespo/rest-entity-manager

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer:

composer require vendor/package-name

Publish the package config (if applicable) and service provider:

php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider"

Key starting points:

  • Filtering: Leverage the new FilterBuilder class in src/Filtering/ for advanced query construction.
  • Interceptors: Register request/response interceptors via the InterceptorManager in config/package.php.
  • Events: Subscribe to package events in EventServiceProvider using the new PackageEvents facade.

First use case: Implement a filtered API endpoint with interceptors:

use Vendor\PackageName\Facades\FilterBuilder;
use Vendor\PackageName\Facades\InterceptorManager;

Route::get('/filtered-data', function () {
    $filteredData = FilterBuilder::table('users')
        ->add('active', true)
        ->withInterceptors()
        ->get();

    return response()->json($filteredData);
});

Implementation Patterns

Core Workflows

  1. Advanced Filtering Pipeline

    // Chain filters with interceptors
    $query = FilterBuilder::table('orders')
        ->where('status', 'pending')
        ->withInterceptors(['logFilter', 'validatePermissions'])
        ->get();
    
  2. Request/Response Interception

    // Register interceptors in config/package.php
    'interceptors' => [
        'request' => [
            'Vendor\PackageName\Interceptors\AuthInterceptor',
            'Vendor\PackageName\Interceptors\RateLimitInterceptor',
        ],
        'response' => [
            'Vendor\PackageName\Interceptors\CacheResponseInterceptor',
        ],
    ],
    
  3. Event-Driven Extensions

    // Listen to filter execution events
    event(new FilterExecuted(
        $query,
        $filteredResults,
        $interceptorsUsed
    ));
    

Integration Tips

  • Middleware vs Interceptors: Use interceptors for package-specific logic; middleware for HTTP-level concerns.
  • Filter Reusability: Store complex filter chains in dedicated service classes.
  • Event Priorities: Override default event priorities in config/package.php under event_priorities.

Gotchas and Tips

Breaking Changes (v1.2)

  • Service Restructuring: Old FilterService is now split into FilterBuilder and FilterExecutor. Update DI bindings.
  • Interceptor API: Parameters are now passed via closures instead of direct method calls. Update existing interceptors.

Debugging

  • Filter Debugging: Enable SQL logging in config/package.php:
    'debug' => [
        'log_filters' => env('APP_DEBUG', false),
    ],
    
  • Interceptor Debugging: Use InterceptorManager::debug() to inspect intercepted requests/responses.

Extension Points

  1. Custom Interceptors

    class CustomInterceptor implements InterceptorContract {
        public function handle($request, Closure $next) {
            // Pre-processing
            $response = $next($request);
            // Post-processing
            return $response;
        }
    }
    
  2. Event Extensions

    // Extend FilterExecuted event
    class CustomFilterEvent extends FilterExecuted {
        public function __construct($query, $results, array $interceptors, $customData) {
            parent::__construct($query, $results, $interceptors);
            $this->customData = $customData;
        }
    }
    
  3. Filter Parameters

    // Dynamic parameter interception
    FilterBuilder::table('products')
        ->addDynamic('price', function ($value) {
            return $value * 1.1; // Apply tax
        });
    

Performance

  • Interceptor Optimization: Avoid heavy operations in interceptors; defer to async jobs if needed.
  • Filter Caching: Cache frequent filter results using FilterBuilder::cache():
    $filtered = FilterBuilder::table('posts')
        ->cache(ttl: 300)
        ->get();
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware