# How to Check Laravel Logs and Verify Livewire Setup

## 1. Checking Laravel Logs for Errors

### Location of Log Files
Laravel logs are stored in: `storage/logs/laravel.log`

### Methods to View Logs:

#### Method 1: View Latest Log File (Windows PowerShell)
```powershell
# View the latest log file
Get-Content "storage\logs\laravel.log" -Tail 50

# Or view the entire file
Get-Content "storage\logs\laravel.log"
```

#### Method 2: Open in Text Editor
- Navigate to: `C:\laragon\www\Gocente\storage\logs\`
- Open `laravel.log` in any text editor (Notepad++, VS Code, etc.)

#### Method 3: Use Tail Command (if available)
```bash
tail -f storage/logs/laravel.log
```

#### Method 4: Search for Specific Errors
```powershell
# Search for "404" errors
Select-String -Path "storage\logs\laravel.log" -Pattern "404"

# Search for "livewire" related errors
Select-String -Path "storage\logs\laravel.log" -Pattern "livewire" -CaseSensitive:$false

# Search for "preview-file" errors
Select-String -Path "storage\logs\laravel.log" -Pattern "preview-file" -CaseSensitive:$false
```

### What to Look For:
- **404 errors**: Route not found
- **403 errors**: Permission/authorization issues
- **500 errors**: Server errors
- **File upload errors**: Issues with file storage
- **Signature validation errors**: URL signing problems

---

## 2. Verifying livewire-tmp Directory

### Check if Directory Exists:
```powershell
# Check if directory exists
Test-Path "storage\app\livewire-tmp" -PathType Container
```

### Check Directory Permissions (Windows):
```powershell
# Get directory permissions
Get-Acl "storage\app\livewire-tmp" | Format-List

# Check if directory is writable
$testFile = "storage\app\livewire-tmp\test-write.tmp"
try {
    "test" | Out-File $testFile -ErrorAction Stop
    Remove-Item $testFile -ErrorAction Stop
    Write-Host "Directory is writable ✓"
} catch {
    Write-Host "Directory is NOT writable ✗"
    Write-Host "Error: $_"
}
```

### Create Directory if It Doesn't Exist:
```powershell
# Create directory if it doesn't exist
if (-not (Test-Path "storage\app\livewire-tmp")) {
    New-Item -ItemType Directory -Path "storage\app\livewire-tmp" -Force
    Write-Host "Created livewire-tmp directory"
} else {
    Write-Host "Directory already exists"
}
```

### Verify Storage Link:
```bash
# Ensure storage link exists
php artisan storage:link
```

---

## 3. Quick Diagnostic Commands

### Run All Checks at Once:
```powershell
# Check 1: Directory exists
Write-Host "`n=== Checking livewire-tmp directory ===" -ForegroundColor Cyan
if (Test-Path "storage\app\livewire-tmp") {
    Write-Host "✓ Directory exists" -ForegroundColor Green
} else {
    Write-Host "✗ Directory does NOT exist" -ForegroundColor Red
    New-Item -ItemType Directory -Path "storage\app\livewire-tmp" -Force
    Write-Host "✓ Created directory" -ForegroundColor Green
}

# Check 2: Directory is writable
Write-Host "`n=== Checking write permissions ===" -ForegroundColor Cyan
$testFile = "storage\app\livewire-tmp\test-write.tmp"
try {
    "test" | Out-File $testFile -ErrorAction Stop
    Remove-Item $testFile -ErrorAction Stop
    Write-Host "✓ Directory is writable" -ForegroundColor Green
} catch {
    Write-Host "✗ Directory is NOT writable" -ForegroundColor Red
    Write-Host "Error: $_" -ForegroundColor Yellow
}

# Check 3: Latest log entries
Write-Host "`n=== Latest log entries (last 10 lines) ===" -ForegroundColor Cyan
if (Test-Path "storage\logs\laravel.log") {
    Get-Content "storage\logs\laravel.log" -Tail 10
} else {
    Write-Host "No log file found" -ForegroundColor Yellow
}

# Check 4: Storage link
Write-Host "`n=== Checking storage link ===" -ForegroundColor Cyan
if (Test-Path "public\storage") {
    Write-Host "✓ Storage link exists" -ForegroundColor Green
} else {
    Write-Host "✗ Storage link does NOT exist" -ForegroundColor Red
    Write-Host "Run: php artisan storage:link" -ForegroundColor Yellow
}
```

---

## 4. Common Issues and Solutions

### Issue: 404 on file preview
**Check:**
1. APP_URL in .env matches your domain
2. Route cache cleared: `php artisan route:clear`
3. Config cache cleared: `php artisan config:clear`

### Issue: Permission denied
**Solution:**
- Ensure web server has write permissions to `storage/app/livewire-tmp`
- On Windows with Laragon, this is usually automatic

### Issue: Directory not found
**Solution:**
- Livewire creates this automatically on first upload
- Or create manually: `New-Item -ItemType Directory -Path "storage\app\livewire-tmp"`

---

## 5. Real-time Monitoring

### Watch Logs in Real-time (PowerShell):
```powershell
Get-Content "storage\logs\laravel.log" -Wait -Tail 20
```

### Filter for Specific Errors:
```powershell
Get-Content "storage\logs\laravel.log" -Wait -Tail 50 | Select-String -Pattern "error|exception|404|403" -CaseSensitive:$false
```

