# Testimonial Management System

## Overview
Complete testimonial CRUD (Create, Read, Update, Delete) system for Tagore College with image support and dynamic display options.

## Features
- ✅ Full CRUD Operations (Create, Read, Update, Delete)
- ✅ Image Upload Support (JPG, PNG, JPEG, WEBP - Max 2MB)
- ✅ Rating System (1-5 Stars)
- ✅ Display Order Management
- ✅ Active/Inactive Status Toggle
- ✅ Two Display Components (Grid & Carousel)
- ✅ Authentication & Authorization
- ✅ Responsive Design

## Installation

### 1. Run Migration
```bash
php artisan migrate
```
This will create the `testimonials` table with the following columns:
- id
- name (Client name)
- title (Job title/designation)
- testimonial (Testimonial text - up to 1000 characters)
- image (Image path)
- rating (1-5 stars)
- order (Display order)
- active (Status: true/false)
- timestamps (created_at, updated_at)

### 2. Files Created

#### Model
- `app/Models/Testimonial.php` - Eloquent model for testimonials

#### Controller
- `app/Http/Controllers/TestimonialController.php` - CRUD operations and data retrieval

#### Views
- `resources/views/testimonial/manage_testimonial.blade.php` - List all testimonials
- `resources/views/testimonial/add_testimonial.blade.php` - Add new testimonial
- `resources/views/testimonial/edit_testimonial.blade.php` - Edit existing testimonial
- `resources/views/testimonial/testimonial_display.blade.php` - Grid display component
- `resources/views/testimonial/testimonial_carousel.blade.php` - Carousel display component

#### Routes
- `GET /testimonial` - Manage testimonials (admin dashboard)
- `GET /testimonial/add` - Add testimonial form
- `POST /testimonial/store` - Store new testimonial
- `GET /testimonial/{id}/edit` - Edit testimonial form
- `PUT /testimonial/{id}` - Update testimonial
- `DELETE /testimonial/{id}` - Delete testimonial

## Usage

### Backend - Admin Dashboard

1. **Access Admin Panel**: Navigate to `/testimonial` (only accessible to authenticated users)

2. **Add Testimonial**:
   - Click "Add Testimonial" button
   - Fill in client name (required)
   - Enter job title/designation (optional)
   - Enter testimonial text (required)
   - Select rating (1-5 stars)
   - Upload client image (optional, supported formats: JPG, PNG, JPEG, WEBP)
   - Set display order (lower number = appears first)
   - Toggle active status to make it visible on frontend
   - Click "Save Testimonial"

3. **Edit Testimonial**:
   - Click the edit button (pencil icon) for any testimonial
   - Modify the details
   - Upload a new image or leave blank to keep existing
   - Click "Update Testimonial"

4. **Delete Testimonial**:
   - Click the delete button (trash icon)
   - Confirm deletion

### Frontend - Display Testimonials

#### Option 1: Grid Display (3 Columns)
Add this line to any Blade template where you want to display testimonials:
```blade
@include('testimonial.testimonial_display')
```

Features:
- Responsive grid layout
- 3 columns on desktop, responsive on mobile
- Shows testimonial preview (first 150 characters)
- Displays client image, name, title, and rating
- Smooth hover animations

#### Option 2: Carousel Display (Slider)
Add this line to any Blade template for carousel/slider view:
```blade
@include('testimonial.testimonial_carousel')
```

Features:
- Bootstrap carousel/slider
- One testimonial at a time
- Navigation arrows for multiple testimonials
- Full testimonial text display
- Auto-responsive with Bootstrap

### Database Schema

```sql
CREATE TABLE testimonials (
    id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(255) NULLABLE,
    title VARCHAR(255) NULLABLE,
    testimonial LONGTEXT NULLABLE,
    image VARCHAR(255) NULLABLE,
    rating INT DEFAULT 5,
    order INT DEFAULT 0,
    active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP NULL,
    updated_at TIMESTAMP NULL
);
```

## Controller Methods

### Public Methods (For Frontend)
- `getActive()` - Returns all active testimonials ordered by display order

### Admin Methods (Protected by Authentication)
- `index()` - Display all testimonials management page
- `create()` - Show add testimonial form
- `store()` - Store new testimonial with image upload
- `edit($id)` - Show edit testimonial form
- `update($id)` - Update testimonial with image replacement
- `destroy($id)` - Delete testimonial and associated image

## Image Handling

- Images are saved in `/public/uploads/testimonials/`
- Filename format: `testimonial_[timestamp].[extension]`
- Maximum file size: 2MB
- Supported formats: JPG, JPEG, PNG, WEBP
- Old images are automatically deleted when replaced
- Images are also deleted when testimonial is deleted

## Security Features

✅ CSRF Protection - All forms are protected with CSRF tokens
✅ Authentication - All admin operations require login
✅ File Validation - Only allowed image formats accepted
✅ File Size Validation - Maximum 2MB enforced
✅ SQL Injection Protection - Uses Eloquent ORM
✅ XSS Protection - Blade templates with proper escaping

## Customization

### Change Grid Layout
Edit `testimonial_display.blade.php` line with `col-lg-4` to adjust columns:
- `col-lg-4` = 3 columns
- `col-lg-6` = 2 columns
- `col-lg-12` = 1 column

### Change Colors
The components use Bootstrap classes. Edit the inline styles in:
- `testimonial_display.blade.php` - Background color, borders, etc.
- `testimonial_carousel.blade.php` - Carousel styling

### Modify Display Order
To sort testimonials differently, edit the `getActive()` method in TestimonialController:
```php
public function getActive()
{
    return Testimonial::where('active', true)
        ->orderBy('order')  // Change this line
        ->orderBy('created_at', 'desc')  // Or add/remove this
        ->get();
}
```

## Troubleshooting

**Issue**: Images not uploading
- Solution: Check if `/public/uploads/testimonials/` directory exists and has write permissions

**Issue**: Testimonials not showing on frontend
- Solution: Ensure testimonials are marked as "Active" in the admin panel

**Issue**: 404 errors on routes
- Solution: Make sure TestimonialController is imported in `routes/web.php`

**Issue**: File size error
- Solution: Check `.env` file for `UPLOAD_MAX_FILESIZE` and `POST_MAX_SIZE` settings

## Future Enhancements
- [ ] Video testimonials support
- [ ] Testimonial categories/departments
- [ ] Approved/Pending status workflow
- [ ] Social media links for testimonials
- [ ] Email notifications for new testimonials
- [ ] Advanced filtering and search in admin panel

## API Endpoints (If needed)

For frontend API access (make sure to add these routes if needed):
```php
Route::get('/api/testimonials', [TestimonialController::class, 'getActive']);
```

## Support
For issues or questions, contact the development team.

---
**Last Updated**: February 13, 2026
**Version**: 1.0
