PHP code example of andrey-vasin / laravel-request-filters
1. Go to this page and download the library: Download andrey-vasin/laravel-request-filters 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/ */
andrey-vasin / laravel-request-filters example snippets
public function rules():array {
return [
'email' => ['quired']
];
}
public function filters():array {
return [
'email' => [new FilterTrim, new FilterSanitizeEmail],
'name' => [new FilterTrim, new FilterSanitizeText, new FilterCapitalize],
'employees.*.name' => [new FilterCapitalize],
'date' => [new FilterTrim, new FilterDate('d/m/Y')]
];
}
public function filters():array {
return [
'email' => 'trim|email',
'name' => 'trim|sanitize|capitalize',
'employees.*.name' => 'capitalize',
'date' => 'trim|date:d/m/Y'
];
}
$input = $request->validated();
echo $input['email'];
//trimmed and sanitized email!