File tree Expand file tree Collapse file tree 4 files changed +73
-0
lines changed
Expand file tree Collapse file tree 4 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "name" : " redaelfillali/laravel-secure-model" ,
3+ "description" : " Eloquent base model with auto-sanitized getters and setters." ,
4+ "type" : " library" ,
5+ "license" : " MIT" ,
6+ "autoload" : {
7+ "psr-4" : {
8+ "Redaelfillali\\ laravel-secure-model\\ " : " src/"
9+ }
10+ },
11+ "require" : {
12+ "php" : " ^8.1" ,
13+ "illuminate/database" : " ^9.0|^10.0|^11.0" ,
14+ "stevebauman/purify" : " ^4.0"
15+ },
16+ "extra" : {
17+ "laravel" : {
18+ "providers" : [
19+ " Redaelfillali\\ laravel-secure-model\\ SecureModelServiceProvider"
20+ ]
21+ }
22+ },
23+ "minimum-stability" : " stable"
24+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Reda \SecureModel ;
4+
5+ use Illuminate \Database \Eloquent \Model ;
6+ use Stevebauman \Purify \Facades \Purify ;
7+
8+ class SecureModel extends Model
9+ {
10+ protected array $ sanitizeAttributes = [];
11+
12+ public function getAttribute ($ key )
13+ {
14+ $ value = parent ::getAttribute ($ key );
15+
16+ if (in_array ($ key , $ this ->sanitizeAttributes ) && is_string ($ value )) {
17+ return Purify::clean ($ value );
18+ }
19+
20+ return $ value ;
21+ }
22+
23+ public function setAttribute ($ key , $ value )
24+ {
25+ if (in_array ($ key , $ this ->sanitizeAttributes ) && is_string ($ value )) {
26+ $ value = Purify::clean ($ value );
27+ }
28+
29+ return parent ::setAttribute ($ key , $ value );
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Reda \SecureModel ;
4+
5+ use Illuminate \Support \ServiceProvider ;
6+
7+ class SecureModelServiceProvider extends ServiceProvider
8+ {
9+ public function boot (): void
10+ {
11+ // Pas forcément besoin d'y mettre quelque chose ici
12+ }
13+
14+ public function register (): void
15+ {
16+ //
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments