PHP code example of aporat / laravel-filter-var
1. Go to this page and download the library: Download aporat/laravel-filter-var 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/ */
aporat / laravel-filter-var example snippets
'providers' => [
// ...
Aporat\FilterVar\Laravel\FilterVarServiceProvider::class,
],
'aliases' => [
// ...
'FilterVar' => Aporat\FilterVar\Laravel\Facades\FilterVar::class,
],
use Aporat\FilterVar\Laravel\Facades\FilterVar;
$userAgent = FilterVar::filterValue('cast:string|trim|strip_tags|escape', $request->header('User-Agent'));
$result = FilterVar::filterValue('trim|uppercase|cast:string', ' hello world ');
// Returns: "HELLO WORLD"
return [
'custom_filters' => [
'media_real_id' => \App\Filters\MediaRealId::class,
],
];
namespace App\Filters;
use Aporat\FilterVar\Contracts\Filter;
class MediaRealId implements Filter
{
public function apply(mixed $value, array $options = []): string
{
$value = (string) $value;
return str_contains($value, '_') ? explode('_', $value, 2)[0] : $value;
}
}
$result = FilterVar::filterValue('media_real_id', '11111_22222');
// Returns: "11111"
$result = app('filter-var')->filterValue('trim', ' hello ');
// Returns: "hello"
bash
php artisan vendor:publish --provider="Aporat\FilterVar\Laravel\FilterVarServiceProvider" --tag="config"