PHP code example of mnabialek / laravel-handy-request

1. Go to this page and download the library: Download mnabialek/laravel-handy-request library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mnabialek / laravel-handy-request example snippets


composer 

App\Http\Requests\MyRequest::replaceDefaultRequest($app);

 $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
 

\App\Http\Requests\MyRequest::replaceDefaultRequest($app);

$kernel->bootstrap();

public function input($key = null, $default = null)
{
   return $this->original($key, $default);
}

use \Mnabialek\LaravelHandyRequest\Traits\HandyRequest;

protected $filters = [
   'trim',
   'checkbox' => [
       'only' => ['terms', 'checkbox'],
       'value' => false,
    ],
    'nullable' => [
       'except' => ['terms', 'active'] 
    ]    
];

protected function modifyInput(array $input) 
{
   $input['test'] = ' abc';
   unset($input['terms']);
   
   return $input;
}

protected $fieldFiltersMethods = [
   'name' => 'filterName',
   'address.*' => 'filterAllAddressFields',
];

protected function filterName($value, $fullKey) 
{
  return 'modified '.$value; 
}

protected function filterAllAddressFields($value, $fullKey) 
{
  if ($fullKey == 'address.street') {
     return $value;
  }
  return 'modified '.$value; 
}

$value = $this->applyFilters($value, $fullKey, $this->normalizedFilters());

protected function registerFilters()
{
   static::registerFilter('trim', \App\RequestFilters\MyCustomTrimFilter::class);
   static::registerFilter('new_filter', \App\RequestFilters\BrandNewFilter::class);
}