# Complete Guide: Checking Laravel Logs & Verifying Livewire Setup

## ✅ Quick Summary

Based on the diagnostic script, here's what we found:
- ✓ **livewire-tmp directory exists** and has 28 files
- ✓ **Directory is writable**
- ✓ **Storage link exists**
- ⚠ **APP_URL needs to be updated** from `http://localhost` to `https://app.gocente.com`

---

## 📋 Part 1: How to Check Laravel Logs

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

### Method 1: View Last 50 Lines (Recommended)
```powershell
Get-Content storage\logs\laravel.log -Tail 50
```

### Method 2: View Last 10 Lines
```powershell
Get-Content storage\logs\laravel.log -Tail 10
```

### Method 3: Watch Logs in Real-Time
```powershell
Get-Content storage\logs\laravel.log -Wait -Tail 20
```
*Press `Ctrl+C` to stop watching*

### 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 file upload errors
Select-String -Path "storage\logs\laravel.log" -Pattern "preview-file|upload-file" -CaseSensitive:$false

# Search for all errors (404, 403, 500, etc.)
Select-String -Path "storage\logs\laravel.log" -Pattern "ERROR|Exception|404|403|500" -CaseSensitive:$false
```

### Method 5: Open in Text Editor
1. Navigate to: `C:\laragon\www\Gocente\storage\logs\`
2. Open `laravel.log` in:
   - Notepad++
   - VS Code
   - Any text editor

### What to Look For in Logs:
- **404 errors**: Route not found (like the preview-file issue)
- **403 errors**: Permission/authorization issues
- **500 errors**: Server errors
- **File upload errors**: Issues with file storage
- **Signature validation errors**: URL signing problems (related to APP_URL)

---

## 📋 Part 2: Verifying livewire-tmp Directory

### Check if Directory Exists
```powershell
Test-Path "storage\app\livewire-tmp" -PathType Container
```
*Returns `True` if exists, `False` if not*

### Check Directory Contents
```powershell
Get-ChildItem "storage\app\livewire-tmp"
```

### Count Files in Directory
```powershell
(Get-ChildItem "storage\app\livewire-tmp" -File).Count
```

### Check if Directory is Writable
```powershell
$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 ✗"
}
```

### Create Directory if Missing
```powershell
if (-not (Test-Path "storage\app\livewire-tmp")) {
    New-Item -ItemType Directory -Path "storage\app\livewire-tmp" -Force
    Write-Host "Created livewire-tmp directory"
}
```

### Verify Storage Link
```powershell
# Check if link exists
Test-Path "public\storage"

# Create link if missing
php artisan storage:link
```

---

## 🔧 Part 3: Fixing the APP_URL Issue

### Current Status
Your `.env` file has:
```
APP_URL=http://localhost
```

### Required Change
Update to:
```
APP_URL=https://app.gocente.com
```

### Steps to Fix:

1. **Open your `.env` file** (in the root directory)

2. **Find the line:**
   ```
   APP_URL=http://localhost
   ```

3. **Change it to:**
   ```
   APP_URL=https://app.gocente.com
   ```

4. **Save the file**

5. **Clear caches:**
   ```powershell
   php artisan config:clear
   php artisan route:clear
   php artisan cache:clear
   ```

6. **Test the file upload again**

### Why This Matters:
- Livewire generates **signed URLs** for file previews
- Signed URLs are based on `APP_URL`
- If `APP_URL` doesn't match your actual domain, the signature validation fails
- This causes **404 errors** when trying to preview uploaded files

---

## 🚀 Part 4: Using the Diagnostic Script

### Run the Complete Diagnostic
```powershell
powershell -ExecutionPolicy Bypass -File check-livewire.ps1
```

### What It Checks:
1. ✓ livewire-tmp directory existence
2. ✓ Directory write permissions
3. ✓ Storage link existence
4. ✓ Latest log entries
5. ✓ Recent Livewire-related errors
6. ✓ APP_URL configuration

### Run Anytime
Run this script whenever you need to:
- Troubleshoot file upload issues
- Verify your setup
- Check for errors
- Verify configuration

---

## 📝 Quick Reference Commands

### View Logs
```powershell
# Last 50 lines
Get-Content storage\logs\laravel.log -Tail 50

# Watch in real-time
Get-Content storage\logs\laravel.log -Wait -Tail 20

# Search for errors
Select-String -Path "storage\logs\laravel.log" -Pattern "404|403|500" -CaseSensitive:$false
```

### Check Directory
```powershell
# Check if exists
Test-Path "storage\app\livewire-tmp"

# List files
Get-ChildItem "storage\app\livewire-tmp"

# Count files
(Get-ChildItem "storage\app\livewire-tmp" -File).Count
```

### Clear Caches
```powershell
php artisan config:clear
php artisan route:clear
php artisan cache:clear
```

### Run Diagnostic
```powershell
powershell -ExecutionPolicy Bypass -File check-livewire.ps1
```

---

## 🐛 Troubleshooting Common Issues

### Issue: 404 on file preview
**Solution:**
1. Update `APP_URL` in `.env` to match your domain
2. Clear caches: `php artisan config:clear && php artisan route:clear`
3. Test again

### Issue: Permission denied
**Solution:**
- On Windows with Laragon, permissions are usually automatic
- If issues persist, check that the web server user has write access to `storage/app/livewire-tmp`

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

### Issue: Storage link missing
**Solution:**
```powershell
php artisan storage:link
```

---

## ✅ Next Steps

1. **Update APP_URL** in your `.env` file to `https://app.gocente.com`
2. **Clear caches** using the commands above
3. **Test file upload** on the CreateBusiness page
4. **Check logs** if issues persist using the commands above
5. **Run diagnostic script** anytime: `powershell -ExecutionPolicy Bypass -File check-livewire.ps1`

---

## 📞 Need More Help?

If you're still experiencing issues after following this guide:

1. **Check the logs** for specific error messages
2. **Run the diagnostic script** to see current status
3. **Verify APP_URL** matches your actual domain
4. **Check browser console** (F12) for JavaScript errors
5. **Verify network tab** in browser DevTools to see the exact request/response

