# Installation Guide

## Requirements

- PHP 8.1 or higher
- Laravel 10.x or 11.x
- MySQL/MariaDB or PostgreSQL

## Step 1: Install Package

```bash
composer require dariusmure/laravel-captcha
```

Or add to your `composer.json`:

```json
{
    "require": {
        "dariusmure/laravel-captcha": "^1.0"
    }
}
```

## Step 2: Publish Assets

```bash
# Publish config
php artisan vendor:publish --provider="DariusMure\Captcha\CaptchaServiceProvider" --tag="captcha-config"

# Publish migrations
php artisan vendor:publish --provider="DariusMure\Captcha\CaptchaServiceProvider" --tag="captcha-migrations"

# Publish views (optional)
php artisan vendor:publish --provider="DariusMure\Captcha\CaptchaServiceProvider" --tag="captcha-views"
```

## Step 3: Run Migrations

```bash
php artisan migrate
```

## Step 4: Configure Provider

Add to your `.env`:

```env
CAPTCHA_ENABLED=true
CAPTCHA_PROVIDER=hcaptcha

# hCaptcha Keys
HCAPTCHA_SITE_KEY=your_site_key_here
HCAPTCHA_SECRET_KEY=your_secret_key_here
```

Get your keys from:
- **hCaptcha**: https://dashboard.hcaptcha.com/
- **reCAPTCHA**: https://www.google.com/recaptcha/admin
- **Turnstile**: https://dash.cloudflare.com/
- **TrustIP**: https://trustip.io/

## Step 5: Add to Forms

```blade
<form method="POST" action="/login">
    @csrf
    <input type="email" name="email">
    <input type="password" name="password">
    
    <x-captcha location="login" />
    
    <button type="submit">Login</button>
</form>
```

## Step 6: Protect Routes

```php
Route::post('/login', [LoginController::class, 'login'])
    ->middleware('captcha:login');
```

## Done! 🎉

Your CAPTCHA is now active and protecting your forms.

## Optional: Admin Panel

Create admin routes:

```php
Route::middleware(['auth', 'admin'])->prefix('admin')->group(function () {
    Route::get('/captcha', [\DariusMure\Captcha\Http\Controllers\CaptchaController::class, 'index'])
        ->name('admin.captcha.index');
    Route::post('/captcha', [\DariusMure\Captcha\Http\Controllers\CaptchaController::class, 'update'])
        ->name('admin.captcha.update');
});
```

## Troubleshooting

### CAPTCHA not showing
- Check `CAPTCHA_ENABLED=true` in `.env`
- Verify keys are correct
- Clear cache: `php artisan config:cache`

### Verification failing
- Check secret key
- Ensure IP is not blocked
- Check rate limits in database

### Need help?
Open an issue: https://github.com/dariusmure/laravel-captcha/issues
