Skip to content

Commit

Permalink
Merge pull request #155 from tabacitu/add-custom-casts-to-refreshed-docs
Browse files Browse the repository at this point in the history
Add custom casts to refreshed docs
  • Loading branch information
mewebstudio authored Oct 14, 2021
2 parents 7ab0f74 + 201f855 commit 1d033fc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ Check out [HTMLPurifier for Laravel 4](https://github.com/mewebstudio/Purifier/t

## Usage

default

Use these methods inside your requests or middleware, wherever you need the HTML cleaned up:

```php
clean(Input::get('inputname'));
```
Expand Down Expand Up @@ -85,6 +87,28 @@ Purifier::clean('This is my H1 title', 'titles', function (HTMLPurifier_Config $
});
```

Alternatively, in Laravel 7+, if you're looking to clean your HTML inside your Eloquent models, you can use our custom casts:

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mews\Purifier\Casts\CleanHtml;
use Mews\Purifier\Casts\CleanHtmlInput;
use Mews\Purifier\Casts\CleanHtmlOutput;

class Monster extends Model
{
protected $casts = [
'bio' => CleanHtml::class, // cleans both when getting and setting the value
'description' => CleanHtmlInput::class, // cleans when setting the value
'history' => CleanHtmlOutput::class, // cleans when getting the value
];
}
```

## Configuration

To use your own settings, publish config.
Expand Down

0 comments on commit 1d033fc

Please sign in to comment.