1. Go to this page and download the library: Download grazulex/laravel-safeguard 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/ */
use Grazulex\LaravelSafeguard\Facades\Safeguard;
// Enable monitoring for specific models
class User extends Model
{
use \Grazulex\LaravelSafeguard\Traits\Auditable;
protected $auditableEvents = ['created', 'updated', 'login'];
}
// Monitor API endpoints
Route::middleware(['safeguard.monitor'])->group(function () {
Route::get('/api/sensitive-data', [ApiController::class, 'getData']);
});
// Custom threat detection
Safeguard::threats()->detect('custom_threat', function ($request) {
return $request->has('suspicious_parameter');
});
use Grazulex\LaravelSafeguard\Testing\SecurityTester;
public function test_sql_injection_protection()
{
SecurityTester::make()
->attemptSqlInjection('/api/users?id=1; DROP TABLE users;--')
->assertBlocked()
->assertThreatLogged('sql_injection');
}
public function test_rate_limiting()
{
SecurityTester::make()
->simulateRequests('/api/endpoint', 100)
->assertRateLimited()
->assertAuditLogged();
}