actengage/sanitize
最新稳定版本:v2.2.0
Composer 安装命令:
composer require actengage/sanitize
包简介
A collection of common sanitizer functions.
README 文档
README
A collection of classes used to sanitize common things like email, phone, and zip codes.
Installation
composer require actengage/sanitize
Publish the Config
You may optionally publish the config file.
php artisan vendor:publish --tag=sanitize-config
Basic Example
use Actengage\Sanitize\Facades\Sanitize; Sanitize::email(' JOHN.doe @gmail '); // johndoe@gmail.com Sanitize::phone('(888) 555-1234'); // 8885551234 Sanitize::zip('12345'); // 12345
Attribute Casts
You can easily cast Eloquent attribute as sanitized values.
use Actengage\Sanitize\Casts\Email; use Actengage\Sanitize\Casts\Phone; use Actengage\Sanitize\Casts\Zip; class User extends Model { protected $guarded = []; protected $casts = [ 'email' => Email::class, 'phone' => Phone::class, 'zip' => Zip::class, ]; } $user = User::create([ 'email' => 'john.doe@gmail.com', 'phone' => '1-800-555-1234', 'zip' => '1234', ]) dd($user->email); // johndoe@gmail.com dd($user->phone); // 8005001234 dd($user->zip); // 01234
Default Sanitizers
You may add to the default sanitizers in the config/sanitize.php.
<?php use Actengage\Sanitize\Sanitizers\Email; use Actengage\Sanitize\Sanitizers\Phone; use Actengage\Sanitize\Sanitizers\Zip; return [ /* |-------------------------------------------------------------------------- | Sanitizers |-------------------------------------------------------------------------- | | This value is an array of invokable classes that implement the Sanitizer | interface. These are the default macros associated with the Sanitizer | instance. | | use Actengage\Sanitize\Facades\Sanitize; | | Sanitize::email('test @test.com'); // test@test.com | Sanitize::phone('(888) 555-1234'); // 8885551234 | Sanitize::zip('12345-1234'); // 123451234 | */ 'sanitizers' => [ 'email' => Email::class, 'phone' => Phone::class, 'zip' => Zip::class, ] ];
Sanitizer Macros
You may also add additional sanitizer functions using the macro.
Sanitize::macro('test', function($value) { return round($value) * 100; }); Sanitize::test(100.1234); // 10000
统计信息
- 总下载量: 1.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-12