Skip to content

Commit 201f855

Browse files
authored
Add custom casts to refreshed docs
1 parent 3ae7e1a commit 201f855

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ Check out [HTMLPurifier for Laravel 4](https://github.com/mewebstudio/Purifier/t
5454

5555
## Usage
5656

57-
default
57+
58+
Use these methods inside your requests or middleware, wherever you need the HTML cleaned up:
59+
5860
```php
5961
clean(Input::get('inputname'));
6062
```
@@ -85,6 +87,28 @@ Purifier::clean('This is my H1 title', 'titles', function (HTMLPurifier_Config $
8587
});
8688
```
8789

90+
Alternatively, in Laravel 7+, if you're looking to clean your HTML inside your Eloquent models, you can use our custom casts:
91+
92+
```php
93+
<?php
94+
95+
namespace App\Models;
96+
97+
use Illuminate\Database\Eloquent\Model;
98+
use Mews\Purifier\Casts\CleanHtml;
99+
use Mews\Purifier\Casts\CleanHtmlInput;
100+
use Mews\Purifier\Casts\CleanHtmlOutput;
101+
102+
class Monster extends Model
103+
{
104+
protected $casts = [
105+
'bio' => CleanHtml::class, // cleans both when getting and setting the value
106+
'description' => CleanHtmlInput::class, // cleans when setting the value
107+
'history' => CleanHtmlOutput::class, // cleans when getting the value
108+
];
109+
}
110+
```
111+
88112
## Configuration
89113

90114
To use your own settings, publish config.

0 commit comments

Comments
 (0)