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

Laminas Filter Laravel Package

laminas/laminas-filter

A collection of reusable data filters for PHP apps. Provides string and numeric normalization, file and HTML filters, and a plugin manager to compose filter chains. Useful for sanitizing and transforming input consistently across Laminas and other frameworks.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer (composer require laminas/laminas-filter). Begin with common built-in filters like StringTrim, Digits, ToNull, and Callback to sanitize incoming request data—especially for form fields or JSON payloads. The entry point is usually the Laminas\Filter\FilterChain or instantiating filters directly (e.g., (new \Laminas\Filter\StringTrim())->filter($input)). For Laravel projects, use it in controllers or form request classes before validation, not instead of it. Check src/ for filter classes—each implements Laminas\Filter\FilterInterface with a single filter() method.

Implementation Patterns

  • Filter Chains: Build sequential transformations using FilterChain, ideal for nested arrays (e.g., trimming all strings in a POST payload).
    $chain = new FilterChain();
    $chain->attach(new StringTrim())
          ->attach(new StringToLower());
    $clean = $chain->filter($input);
    
  • Standalone Usage: Use individual filters in services where input normalization is needed (e.g., transforming API request parameters before passing to a domain service).
  • Laravel Integration: Inject filters into form request rules() or custom formatters—don’t overload validation rules with transformations. For example, strip HTML tags using HtmlEntities before Rule::required|string|max:255.
  • Extensibility: Extend Laminas\Filter\FilterInterface to create domain-specific filters (e.g., SanitizeSlug, NormalizePhone), and register them in service containers if using Laravel’s DI.
  • Pipeline Use: Combine with laminas/laminas-validator for robust input pipelines—filter first, validate second.

Gotchas and Tips

  • Filters are not idempotent by default: Applying the same filter multiple times (e.g., StringTrim on already-trimmed input) may still trigger processing—test edge cases (especially Digits or Int filters on non-numeric strings).
  • Null vs. '': Filters like Digits return empty string '' for invalid input, not null. Use ToNull after such filters to convert empty strings to null.
  • Filter order matters: StringToLower before StringTrim vs. after can affect case-sensitivity in whitespace logic (though rare, ensure consistency).
  • Avoid over-filtering: Don’t sanitize data before knowing its type—e.g., don’t cast to Int on optional numeric fields where null is acceptable.
  • Laravel Tip: Use collect($request->all())->map(fn($value) => (new StringTrim())->filter($value)) for bulk trimming, but prefer targeted filtering per field instead of blanket transformations to avoid data loss (e.g., trimming passwords or base64 content breaks them).
  • Debug tip: Implement __toString() or use var_dump in a closure filter to trace intermediate values in chains.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope