PHP code example of okipa / laravel-request-sanitizer
1. Go to this page and download the library: Download okipa/laravel-request-sanitizer 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/ */
okipa / laravel-request-sanitizer example snippets
use Okipa\LaravelRequestSanitizer\RequestSanitizer;
class Request extends RequestSanitizer
{
// your laravel project base request custom features.
}
namespace App\Http\Requests;
use Okipa\LaravelRequestSanitizer\RequestSanitizer;
class EditUserRequest extends RequestSanitizer
{
protected $sanitizeEntries = true; // default value
protected $exceptFromSanitize = ['user.phone_number']; // except the phone number from the sanitizing treatment in order to keep the phone number first zero (example : 0240506070)
protected $excludeNullEntries = true; // default value
protected $exceptFromNullExclusion = ['user.company_name']; // is kept in the request keys even if its value is null
protected $safetyChecks = ['user.newsletter.subscription' => 'boolean', 'user.permissions' => 'array']; // will make sure that the declared keys will be returned with a default value if not found in the request
/**
* Execute some treatments just after the request creation
*/
public function before()
{
// execute your custom request treatments here
$this->merge(['formatted_date' => Carbon::createFromFormat('d/m/Y H:i:s', $this->input('user.created_at')->toDateTimeString()]);
}
/**
* Set the validation rules
*
* @return array
*/
public function rules()
{
return [
// other rules ...
'user.phone_number' => '