PHPackages                             redaelfillali/laravel-secure-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. redaelfillali/laravel-secure-model

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

redaelfillali/laravel-secure-model
==================================

Eloquent base model with auto-sanitized getters and setters.

1.1.0(1mo ago)0296MITPHPPHP ^8.1|^8.2|^8.3|^8.4

Since Apr 22Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/redafillali/laravel-secure-model)[ Packagist](https://packagist.org/packages/redaelfillali/laravel-secure-model)[ RSS](/packages/redaelfillali-laravel-secure-model/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (6)Used By (0)

Laravel Secure Model
====================

[](#laravel-secure-model)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e087fa210f88ac65037cb62628511574d5b729589c2739d3f6d9870ed143407a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656461656c66696c6c616c692f6c61726176656c2d7365637572652d6d6f64656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/redaelfillali/laravel-secure-model)[![PHP Version](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)](https://www.php.net/)[![Laravel Version](https://camo.githubusercontent.com/e5cb0ed82441ce3b9e78b6d861bb337d7468b6ab12af897b81334748f8676c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d392d2d31332d726564)](https://laravel.com/)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

An Eloquent base model that automatically sanitizes specified attributes on **get** and **set**, protecting your application from XSS vulnerabilities out of the box.

---

Features
--------

[](#features)

- Automatically purifies HTML on both read (`getAttribute`) and write (`setAttribute`)
- Powered by [stevebauman/purify](https://github.com/stevebauman/purify) (HTMLPurifier wrapper)
- Zero-configuration: just list the attributes to sanitize
- Supports Laravel 9, 10, 11, 12, and 13
- Supports PHP 8.1, 8.2, 8.3, and 8.4

---

Requirements
------------

[](#requirements)

DependencyVersionPHP^8.1 | ^8.2 | ^8.3 | ^8.4Laravel^9.0 | ^10.0 | ^11.0 | ^12.0 | ^13.0stevebauman/purify^6.3---

Installation
------------

[](#installation)

```
composer require redaelfillali/laravel-secure-model
```

The service provider is registered automatically via Laravel's package auto-discovery.

Optionally publish the [Purify configuration](https://github.com/stevebauman/purify#configuration) to customise the HTML rules:

```
php artisan vendor:publish --provider="Stevebauman\Purify\PurifyServiceProvider"
```

---

Usage
-----

[](#usage)

Extend `SecureModel` instead of the default Eloquent `Model` and declare the attributes you want automatically sanitized in the `$sanitizeAttributes` array:

```
