PHP code example of intentphp / guard

1. Go to this page and download the library: Download intentphp/guard 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/ */

    

intentphp / guard example snippets


// guard:ignore dangerous-query-input
->orderBy($request->input('sort'))

->orderBy($request->input('sort')) // guard:ignore dangerous-query-input

// guard:ignore all
->whereRaw($request->input('filter'))

'allow_inline_ignores' => false,

// config/guard.php

return [
    // Structured (recommended). The legacy flat 'auth_middlewares' key still
    // works for backward compatibility but is deprecated.
    'route_authorization' => [
        'auth_middleware_exact' => [
            'auth',
            'auth:sanctum',
            'Filament\\Http\\Middleware\\Authenticate',
        ],
        // 'auth' matches both auth:sanctum and auth.basic (dotted aliases).
        'auth_middleware_prefixes' => ['auth'],
        // Any FQCN ending in \Authenticate (namespace-anchored) counts as auth,
        // so custom App\Http\Middleware\Authenticate is recognised by default.
        'auth_middleware_suffixes' => ['\\Authenticate'],

        // Framework-standard guest routes Guard skips by default.
        'skip_guest_routes' => ['login', 'register', 'forgot-password', /* ... */],
        // Framework-standard infrastructure routes Guard skips by default.
        'skip_infra_routes' => ['up', 'health', 'sanctum/csrf-cookie', 'livewire/*', /* ... */],
    ],

    // Business-specific public routes (in addition to the skip lists above).
    'public_routes' => [],

    'ai' => [
        'enabled' => env('GUARD_AI_ENABLED', false),
        'driver' => env('GUARD_AI_DRIVER', 'null'), // null|cli|openai|auto

        'cli' => [
            'command' => env('GUARD_AI_CLI', 'claude'),
            'args' => env('GUARD_AI_CLI_ARGS', ''),
            'timeout' => env('GUARD_AI_CLI_TIMEOUT', 60),
            'expects_json' => env('GUARD_AI_CLI_JSON', false),
            'adapter' => env('GUARD_AI_CLI_ADAPTER', 'auto'),
            'prompt_prefix' => env('GUARD_AI_CLI_PROMPT_PREFIX', ''),
        ],

        'openai' => [
            'base_url' => env('GUARD_AI_BASE_URL', 'https://api.openai.com/v1'),
            'api_key' => env('GUARD_AI_API_KEY', ''),
            'model' => env('GUARD_AI_MODEL', 'gpt-4.1-mini'),
            'timeout' => env('GUARD_AI_TIMEOUT', 30),
            'max_tokens' => env('GUARD_AI_MAX_TOKENS', 1024),
        ],
    ],

    'cache' => [
        'enabled' => env('GUARD_CACHE_ENABLED', true),
    ],

    'allow_inline_ignores' => true,
];
bash
composer guard:baseline
php artisan guard:scan --baseline --strict
bash
php artisan vendor:publish --tag=guard-config
bash
# Template-based patches
php artisan guard:fix

# Include AI-assisted patches for findings where templates fail
php artisan guard:fix --ai

# Fix only changed files
php artisan guard:fix --changed
php artisan guard:fix --staged
php artisan guard:fix --changed --base=origin/main
bash
# Generate tests (skip existing files)
php artisan guard:testgen

# Overwrite existing generated tests
php artisan guard:testgen --overwrite
bash
php artisan guard:doctor