# OIA Alert System - Quick Reference Guide

## Quick Start (30 seconds)

```bash
cd d:\Ai-asset\OIA-Alert-System
cp .env.example .env
php artisan key:generate
php artisan migrate --seed
php artisan storage:link
php artisan serve
```

Then visit: **http://localhost:8000**
- Email: `test@example.com`
- Password: `password`

---

## File Structure Quick Map

```
Controllers → app/Http/Controllers/
├── AlertController.php (Alert CRUD)
├── DashboardController.php (Dashboard stats)
├── NotificationController.php (Notifications)
└── ProfileController.php (User management)

Models → app/Models/
├── Alert.php
├── AlertType.php
├── Notification.php
└── User.php

Views → resources/views/
├── layouts/app.blade.php (Main template)
├── dashboard.blade.php
├── alerts/ (Alert pages)
│   ├── create.blade.php
│   ├── index.blade.php
│   ├── show.blade.php
│   ├── edit.blade.php
│   └── oia-alerts.blade.php
└── profile/ (Profile pages)
    ├── show.blade.php
    ├── edit.blade.php
    └── password.blade.php

Routes → routes/
├── web.php (Main routes)
└── auth.php (Auth routes - built-in)

Database → database/
├── migrations/ (Schema)
│   ├── users_table
│   ├── alert_types_table
│   ├── alerts_table
│   └── notifications_table
└── seeders/
    ├── DatabaseSeeder.php
    └── AlertTypeSeeder.php
```

---

## Common Tasks

### Add New Alert Type

Edit `database/seeders/AlertTypeSeeder.php`:

```php
$types = [
    ['name' => 'New Type', 'description' => 'Description', 'icon' => '🎯'],
];
```

Then run:
```bash
php artisan db:seed --class=AlertTypeSeeder
```

---

### Modify Alert Table

Create migration:
```bash
php artisan make:migration add_column_to_alerts_table
```

Edit migration file, then run:
```bash
php artisan migrate
```

---

### Add New Route

Edit `routes/web.php`:

```php
Route::middleware(['auth'])->group(function () {
    Route::get('/new-page', [NewController::class, 'index'])->name('new.index');
});
```

---

### Create New View

1. Create file: `resources/views/new-page.blade.php`
2. Use layout:
```blade
@extends('layouts.app')
@section('title', 'Page Title')
@section('content')
    <!-- Your content here -->
@endsection
```

---

### Check User Alerts

In Laravel Tinker:
```bash
php artisan tinker
```

```php
$user = User::find(1);
$user->alerts()->get();
$user->alerts()->where('status', 'pending')->count();
```

---

## Important Directories

| Directory | Purpose |
|-----------|---------|
| `app/` | Application code |
| `storage/app/public/` | Uploaded files |
| `storage/logs/` | Log files |
| `routes/` | Route definitions |
| `resources/views/` | Templates |
| `database/migrations/` | Schema changes |
| `config/` | Configuration files |
| `public/storage/` | Symlinked uploads |

---

## Key Files to Edit

| File | Purpose |
|------|---------|
| `routes/web.php` | Add/modify routes |
| `resources/views/layouts/app.blade.php` | Change design/layout |
| `app/Http/Controllers/` | Business logic |
| `.env` | Configuration |
| `config/` | App settings |

---

## Artisan Commands Reference

### Database
```bash
php artisan migrate              # Run migrations
php artisan migrate:rollback     # Undo migrations
php artisan migrate:refresh      # Reset DB
php artisan migrate:refresh --seed # Reset + seed
php artisan db:seed              # Run seeders
php artisan db:seed --class=AlertTypeSeeder
```

### Cache & Config
```bash
php artisan config:clear         # Clear config cache
php artisan cache:clear          # Clear cache
php artisan view:clear           # Clear view cache
php artisan optimize:clear       # Clear all caches
```

### Generators
```bash
php artisan make:model Alert --migration  # Model + migration
php artisan make:controller AlertController  # Controller
php artisan make:migration table_name     # Migration only
php artisan make:request AlertRequest    # Form request
```

### Debugging
```bash
php artisan tinker               # REPL shell
php artisan serve                # Start dev server
php artisan serve --port=8001    # Custom port
php artisan route:list           # Show all routes
```

---

## Common Error Solutions

| Error | Solution |
|-------|----------|
| Class not found | `composer dump-autoload` |
| Route not found | `php artisan config:clear` |
| View not found | `php artisan view:clear` |
| File upload fails | `php artisan storage:link` |
| DB connection error | Check `.env` credentials |
| Permission denied | `chmod -R 755 storage` |

---

## Database Quick Reference

### Create Alert (Tinker)
```php
$user = User::first();
Alert::create([
    'user_id' => $user->id,
    'alert_type_id' => 1,
    'title' => 'Test Alert',
    'description' => 'Test description',
    'severity' => 'high',
    'status' => 'pending'
]);
```

### Query Examples
```php
// User's alerts
$user->alerts()->get();

// Pending alerts
Alert::where('status', 'pending')->get();

// Critical alerts
Alert::where('severity', 'critical')->count();

// Recent alerts
Alert::latest()->limit(5)->get();

// By type
AlertType::find(1)->alerts()->get();
```

---

## Authorization Quick Check

### Check if user owns alert
```php
if ($alert->user_id === Auth::id()) {
    // User owns this alert
}
```

### Using Policy
```php
// In controller
$this->authorize('update', $alert);

// In view
@can('update', $alert)
    <a href="{{ route('alerts.edit', $alert) }}">Edit</a>
@endcan
```

---

## Frontend Customization

### Change Colors

Edit `resources/views/layouts/app.blade.php`:

```css
:root {
    --orange: #ff5106;      /* Primary color */
    --white: white;
    --black: #111;          /* Text color */
    --border-color: #efefef; /* Border color */
}
```

### Add New Button Style

```html
<button class="btn btn-custom">Click me</button>
```

Then add CSS:
```css
.btn-custom {
    background-color: #your-color;
    color: white;
}
```

### Modify Layout

Edit `resources/views/layouts/app.blade.php` directly. The entire layout is there with embedded CSS.

---

## Navigation Items

Located in `resources/views/layouts/app.blade.php`:

```blade
<!-- Add new menu item -->
<a href="{{ route('new-route') }}" class="lb-item">
    <div class="ib-icon">SVG ICON HERE</div>
    <div>Label</div>
</a>
```

---

## Validation Messages

Customize in `.env`:

```env
# Add to .env if needed
VALIDATION_LOCALE=en
```

Edit `resources/lang/en/validation.php` for custom messages.

---

## Deployment Checklist

- [ ] Set `APP_DEBUG=false` in `.env`
- [ ] Set `APP_ENV=production`
- [ ] Update `APP_URL`
- [ ] Configure proper database
- [ ] Set up mail settings
- [ ] Run `php artisan config:cache`
- [ ] Set proper file permissions
- [ ] Enable HTTPS
- [ ] Run migrations: `php artisan migrate --force`

---

## Security Reminders

✓ CSRF tokens on all forms  
✓ Passwords hashed with bcrypt  
✓ Authorization policies enforced  
✓ File uploads validated  
✓ SQL injection prevented  

---

## Performance Tips

1. **Pagination**: Defaults to 10 items per page
2. **Eager Loading**: Relationships loaded efficiently
3. **Caching**: Use `cache()` helper for queries
4. **Indexing**: Foreign keys indexed in DB
5. **Logging**: Check `storage/logs/` for issues

---

## Useful Resources

- [Laravel Docs](https://laravel.com/docs)
- [Eloquent Docs](https://laravel.com/docs/eloquent)
- [Blade Templates](https://laravel.com/docs/blade)
- [Form Validation](https://laravel.com/docs/validation)
- [Authorization](https://laravel.com/docs/authorization)
- [File Storage](https://laravel.com/docs/filesystem)

---

## Support Matrix

| Layer | Technology |
|-------|------------|
| Framework | Laravel 11 |
| Database | SQLite/MySQL |
| Frontend | Blade/HTML/CSS |
| JavaScript | Vanilla JS |
| Auth | Laravel Breeze |
| File Storage | Laravel Storage |

---

## Version Info

```
Laravel: 11.x
PHP: 8.1+
Composer: Latest
Node: Optional (for assets)
```

---

This quick reference provides everything you need to work with the OIA Alert System.

For detailed information, refer to:
- **SETUP.md** - Installation & configuration
- **FEATURES.md** - Complete feature list
- **README.md** - Project overview
