# 📚 Library Management System

A complete, beginner-friendly Library Management System built with simple Laravel routes, controllers, direct database queries, and Blade views. This system manages books, issues, and returns with AJAX-based CRUD operations.

## ✨ Features

### 1. **📖 Responsive Navigation Bar**
- Bootstrap navbar with menu items:
  - Books Catalog
  - Add Books
  - Issue Books
  - Issue History
- Fully responsive design for mobile and desktop

### 2. **➕ Add Books Module**
- **Form Fields:**
  - Title (required)
  - Subtitle (optional)
  - Author Name
  - Category
  - Language
  - ISBN Number (unique)
  - DDC (Dewey Decimal Classification)
  - Publisher
  - Publish Year
  - Edition
  - Number of Pages
  - Book Format (Hardcover, Paperback, eBook, Audiobook)
  - Shelf Location
  - Quantity
  - Book Cover Image Upload
- AJAX form submission (no page reload)
- File upload support (JPEG, PNG, JPG, GIF - max 2MB)
- Input validation with feedback

### 3. **📚 Books Catalog/Listing**
- Bootstrap responsive table displaying:
  - Book Cover Image
  - Title & Subtitle
  - Author Name
  - ISBN
  - Category (with badge)
  - Total Quantity
  - Available Copies (color-coded badge)
  - Shelf Location
- **Action Buttons:**
  - Edit (opens modal form)
  - Delete (with confirmation)
- AJAX-based edit/delete operations
- Empty state message with quick link to add books

### 4. **✏️ Update Books Module**
- Pre-filled edit form in modal
- Update using AJAX (no page reload)
- Success message display
- Image replacement capability
- Available copies auto-calculation

### 5. **📋 Issue Books Module**
- **Form Fields:**
  - Select Book (dropdown with available copies)
  - Student/User Name
  - Email Address (optional)
  - Issue Date
  - Return Date (validated to be after issue date)
- Automatic available copies reduction
- Book return tracking

### 6. **📊 Issue History/Management**
- Three-view tabs:
  - **All Issues:** Complete history of all book issues
  - **Active Issues:** Currently issued books (shows overdue status)
  - **Returned Issues:** Books that have been returned
- Columns: Book, Student, Issue Date, Return Date, Actual Return, Status
- **Action:** Mark book as returned (with confirmation)
- Status badges (Issued, Returned, Overdue)

### 7. **🔐 Technical Features**
- AJAX-based CRUD operations (no page reloads)
- jQuery for client-side operations
- Bootstrap 5 responsive UI
- Form validation (client & server-side)
- Success/error alert notifications
- CSRF protection
- Image management (upload & delete)
- RESTful API endpoints

## 📋 System Requirements

- PHP 8.1+
- Laravel 11.x
- MySQL 8.0+
- Bootstrap 5.3
- jQuery 3.6+

## 🚀 Installation & Setup

### 1. Clone/Download the Project
```bash
git clone <repository-url>
cd LMS
```

### 2. Install Dependencies
```bash
composer install
npm install
```

### 3. Environment Setup
```bash
cp .env.example .env
php artisan key:generate
```

### 4. Database Configuration
Update your `.env` file:
```env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lms_database
DB_USERNAME=root
DB_PASSWORD=
```

### 5. Run Migrations & Seeders
```bash
php artisan migrate
php artisan db:seed
```

This will create:
- `books` table
- `issues` table
- 8 sample books for testing

### 6. Create Upload Directory
```bash
mkdir -p public/uploads/books
```

### 7. Start Development Server
```bash
php artisan serve
```

Visit: `http://localhost:8000`

## 📁 Project Structure

```
resources/
├── views/
│   ├── layouts/
│   │   └── app.blade.php           # Main layout with navbar
│   ├── books/
│   │   ├── index.blade.php         # Books listing
│   │   ├── create.blade.php        # Add book form
│   │   └── edit.blade.php          # Edit book form
│   └── issues/
│       ├── index.blade.php         # Issue history
│       └── create.blade.php        # Issue book form

app/Http/Controllers/
├── BookController.php              # Book CRUD operations
└── IssueController.php            # Book issue operations

database/
├── migrations/
│   ├── *_create_books_table.php
│   └── *_create_issues_table.php
└── seeders/
    └── BookSeeder.php             # Sample data

routes/
└── web.php                         # Application routes
```

## 🛣️ API Endpoints

### Books
- `GET /books` - List all books
- `GET /books/create` - Show add book form
- `POST /books` - Store new book
- `GET /books/{id}/edit` - Show edit form
- `PUT /books/{id}` - Update book
- `DELETE /books/{id}` - Delete book
- `GET /books/get-all` - Get all books (JSON)
- `GET /books/get/{id}` - Get single book (JSON)

### Issues
- `GET /issues` - List all issues
- `GET /issues/create` - Show issue book form
- `POST /issues` - Create new issue
- `PUT /issues/{id}/return` - Mark book as returned
- `GET /issues/available-books` - Get books with available copies (JSON)

## 📊 Database Schema

### Books Table
| Column | Type | Notes |
|--------|------|-------|
| id | int | Primary key |
| title | string | Book title |
| subtitle | string | Optional |
| author | string | Author name |
| category | string | Book category |
| language | string | Language |
| isbn | string | Unique ISBN |
| ddc | string | Dewey Decimal |
| publisher | string | Publisher name |
| publish_year | year | Publication year |
| edition | string | Edition info |
| number_of_pages | int | Total pages |
| book_format | string | Format type |
| shelf_location | string | Shelf location |
| quantity | int | Total quantity |
| available_copies | int | Available copies |
| book_cover | string | Image path |
| timestamps | - | created_at, updated_at |

### Issues Table
| Column | Type | Notes |
|--------|------|-------|
| id | int | Primary key |
| book_id | int | Foreign key to books |
| student_name | string | Student name |
| student_email | string | Student email |
| issue_date | date | Date of issue |
| return_date | date | Expected return date |
| actual_return_date | date | Actual return date |
| status | enum | 'issued' or 'returned' |
| timestamps | - | created_at, updated_at |

## 🎨 UI Features

### Bootstrap Components Used
- Navbar with collapse
- Cards for forms
- Responsive tables
- Modals for editing
- Badges for status
- Alerts for notifications
- Tabs for issue filtering
- Tooltips for actions

### JavaScript Features
- AJAX form submission
- Dynamic table updates
- Modal management
- Form validation
- Auto-calculate dates
- Confirmation dialogs
- Loading states

## 🔍 Sample Data

The seeder includes 8 sample books:
1. The Art of Computer Programming
2. Design Patterns
3. Clean Code
4. The Pragmatic Programmer
5. To Kill a Mockingbird
6. 1984
7. The Great Gatsby
8. A Brief History of Time

## ✅ Validation Rules

### Books
- **Title:** Required, max 255 chars
- **Author:** Required, max 255 chars
- **ISBN:** Required, unique, max 20 chars
- **Category:** Required, max 100 chars
- **Quantity:** Required, min 1
- **Book Cover:** Optional, max 2MB, images only

### Issues
- **Book ID:** Required, exists in books table
- **Student Name:** Required, max 255 chars
- **Return Date:** Required, must be after issue date
- **Available Copies:** Must be > 0 for selected book

## 🚀 Usage Guide

### Adding a Book
1. Click "Add Books" in navbar
2. Fill all required fields
3. Optional: Upload book cover image
4. Click "Add Book" button
5. Success message appears and redirects to catalog

### Viewing Books
1. Click "Books Catalog" to view all books
2. See all book details in table format
3. View cover image if uploaded
4. Check available copies

### Editing a Book
1. In Books Catalog, click "Edit" button
2. Modal opens with pre-filled data
3. Modify details as needed
4. Optional: Change cover image
5. Click "Update Book"
6. Success message and refresh

### Deleting a Book
1. In Books Catalog, click "Delete" button
2. Confirmation dialog appears
3. Confirm deletion
4. Book removed from table

### Issuing a Book
1. Click "Issue Books" in navbar
2. Select book from dropdown (shows available copies)
3. Enter student name
4. Optional: Enter email
5. Select issue and return dates
6. Click "Issue Book"
7. Available copies automatically reduced

### Viewing Issues
1. Click "Issue History" in navbar
2. Switch between tabs: All/Active/Returned
3. View all issue details
4. Check overdue status (active issues)
5. Mark book as returned

## 🐛 Troubleshooting

### File Upload Not Working
- Ensure `public/uploads/books` directory exists
- Check file permissions
- Verify file size is under 2MB

### Database Connection Error
- Check `.env` database credentials
- Verify MySQL is running
- Run: `php artisan migrate --fresh`

### AJAX Errors
- Check browser console for errors
- Verify CSRF token in meta tag
- Clear browser cache

### Images Not Displaying
- Check public path is accessible
- Verify image file format
- Ensure correct file permissions

## 📝 Notes

- This system is optimized for beginners
- All operations use CSRF protection
- No authentication required (can be added)
- Suitable for small to medium libraries
- Easy to extend with additional features

## 🔄 Future Enhancements

- User authentication & roles
- Book categories management
- Member management
- Fine calculation for overdue books
- Staff dashboard with analytics
- Book search & filter
- Export to PDF/Excel
- Email notifications
- SMS alerts

## 📄 License

This project is open source and available under the MIT License.

## 👨‍💻 Author

Created as a beginner-level Library Management System tutorial.

## 📞 Support

For issues or questions, please contact the development team.

---

**Happy Library Managing! 📚**
