2017 © Pedro Peláez
 

library laravel-reformulator

Laravel middleware to filter, sanitize, parse and transform request input data.

image

fewagency/laravel-reformulator

Laravel middleware to filter, sanitize, parse and transform request input data.

  • Monday, December 5, 2016
  • by bjuppa
  • Repository
  • 4 Watchers
  • 2 Stars
  • 110 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Reformulator

Laravel middleware to filter, sanitize, parse and transform request input data., (*1)

Note: I'd recommend using Laravel's FormRequests instead of this package's middleware if you wish to manipulate the incomming request before validation and other processing. Your intentions will be easier to understand if manipulation is done in your customized prepareForValidation() method of your FormRequest instead of hidden away in a middleware declared who knows where., (*2)

Also, since Laravel 5.4 there are already middleware for trimming strings and converting empty strings to null applied by default, so this package has been superfluous for quite some time., (*3)

Installation & Configuration

composer require fewagency/laravel-reformulator, (*4)

Register each middleware you want to use in the $routeMiddleware array in app/Http/Kernel.php of your Laravel app:, (*5)

'reformulator.trim' => \FewAgency\Reformulator\Middleware\TrimInput::class,
'reformulator.strip_repeats' => \FewAgency\Reformulator\Middleware\StripRepeatNonWordCharsFromInput::class,
'reformulator.filter' => \FewAgency\Reformulator\Middleware\FilterInput::class,

'reformulator.remove_empty' => \FewAgency\Reformulator\Middleware\RemoveEmptyInput::class,
'reformulator.clean_array' => \FewAgency\Reformulator\Middleware\CleanArrayInput::class,

'reformulator.concatenate' => \FewAgency\Reformulator\Middleware\ConcatenateInput::class,
'reformulator.explode' => \FewAgency\Reformulator\Middleware\ExplodeInput::class,

'reformulator.datetime-local' => \FewAgency\Reformulator\Middleware\DatetimeLocalInput::class,
'reformulator.datetime' => \FewAgency\Reformulator\Middleware\DatetimeInput::class,

Usage and parameters to each middleware is currently documented in each of the classes but in general, most of them take a list of field names as middleware parameters., (*6)

Read more in the Laravel docs for middleware., (*7)

Principles

Some would argue that it's not a good idea to mutate the Request object, for examples see GrahamCampbell's comments on Laravel issue 10725., (*8)

My opinion is that it makes sense to modify data in the request when: - The same transformations could instead have been done on the client side before submitting, or substitutes a shortcoming in the transmission method (e.g. it's not possible to submit an empty array) - The transformations absolutely can't go against the user's intention (as we're not giving the user a chance to approve the change) - The transformations doesn't break repopulating the view (i.e. form), (*9)

Listen to Full Stack Radio ep. 54 with Jonathan Reinink and host Adam Wathan for an interesting conversation about form handling. Adam then went on and created a gist of macros to add filtering functions to Laravel Requests., (*10)

Authors

I, Björn Nilsved, created this package while working at FEW., (*11)

The Versions

05/12 2016

dev-master

9999999-dev

Laravel middleware to filter, sanitize, parse and transform request input data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bjorn Nilsved

laravel middleware filter form request input transform sanitize datetime trim explode datetime-local implode