# S3 Image Storage Setup

This project has been configured to store user-uploaded images on Amazon S3 while keeping trivial site assets local.

## Configuration Steps

1. **Environment Variables**: Update your `.env` file with your AWS credentials:
   ```
   AWS_ACCESS_KEY_ID=your_access_key_here
   AWS_SECRET_ACCESS_KEY=your_secret_key_here
   AWS_DEFAULT_REGION=us-east-1
   AWS_BUCKET=your_bucket_name_here
   AWS_URL=
   AWS_ENDPOINT=
   AWS_USE_PATH_STYLE_ENDPOINT=false
   ```

2. **S3 Bucket Setup**:
   - Create an S3 bucket in your AWS console
   - Set bucket policy to allow public read access for images
   - Configure CORS if needed for direct uploads

3. **Storage Configuration**:
   - Added `images` disk in `config/filesystems.php` pointing to S3
   - All item photos now use the `images` disk instead of `public`

## What Changed

### Files Modified:
- `config/filesystems.php` - Added `images` disk configuration
- `app/Http/Controllers/ItemController.php` - Updated photo storage methods
- `app/Http/Controllers/Admin/AdminItemController.php` - Updated photo deletion
- `app/Models/ItemPhoto.php` - Added URL accessors for S3 compatibility

### New Files:
- `app/Console/Commands/MigrateImagesToS3.php` - Command to migrate existing images

## Migration Process

1. **Configure S3**: Set up your AWS credentials in `.env`

2. **Test Configuration**: 
   ```bash
   php artisan tinker
   Storage::disk('images')->put('test.txt', 'test content');
   ```

3. **Migrate Existing Images** (dry run first):
   ```bash
   php artisan images:migrate-to-s3 --dry-run
   php artisan images:migrate-to-s3
   ```

4. **Verify**: Check that new uploads go to S3 and existing images display correctly

## Storage Behavior

- **Item Photos**: Stored on S3 via `images` disk
- **Site Assets**: Remain local (CSS, JS, static images)
- **Existing Photos**: Migrated via command, local files preserved for safety

## Troubleshooting

- Ensure S3 bucket has proper permissions
- Check AWS credentials are valid
- Verify bucket region matches configuration
- Test with a small upload first before migrating all images