PHP code example of touhidurabir / laravel-model-sanitize

1. Go to this page and download the library: Download touhidurabir/laravel-model-sanitize library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

touhidurabir / laravel-model-sanitize example snippets


$user = User::create([
    'email' => '[email protected]',
    'password' => Hash::make('password')
]);

User::create([
    'email' => '[email protected]', 
    'password' => 'password', 
    'data' => 'some data'
]);

$data = [
    'email' => '[email protected]', 
    'password' => 'password', 
    'data' => 'some data'
];

User::create($data);

$validated = $request->validated();

$user = User::create($validated);

$profile = $user->profile->create($validated);

use Touhidurabir\ModelSanitize\Sanitizable;
use Illuminate\Database\Eloquent\Model;

class User extends Model {
    
    use Sanitizable;
}

$data = [
    'email' => '[email protected]', 
    'password' => 'password', 
    'data' => 'some data', 
    'name' => 'Test User'
];

User::sanitize($data);

[
    'email' => '[email protected]', 
    'password' => 'password', 
    'name' => 'Test User'
]

$data = [
    'email' => '[email protected]', 
    'password' => 'password', 
    'data' => 'some data', 
    'name' => 'Test User'
];

User::gibberish($data);

[
    'data' => 'some data', 
]

User::disableSanitization(); // disable the sanitization process
User::enableSanitization();  // enable the sanitization process if previously disabled