﻿<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>

<p align="center">
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>

## About Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:

- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).

Laravel is accessible, powerful, and provides tools required for large, robust applications.

## Learning Laravel

Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.

You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.

If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.

## Laravel Sponsors

We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).

### Premium Partners

- **[Vehikl](https://vehikl.com/)**
- **[Tighten Co.](https://tighten.co)**
- **[WebReinvent](https://webreinvent.com/)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
- **[Cyber-Duck](https://cyber-duck.co.uk)**
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
- **[Jump24](https://jump24.co.uk)**
- **[Redberry](https://redberry.international/laravel/)**
- **[Active Logic](https://activelogic.com)**
- **[byte5](https://byte5.de)**
- **[OP.GG](https://op.gg)**

## Contributing

Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).

## Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).

## Security Vulnerabilities

If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.

## License

The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

---

# Pathshalaa API

A Laravel 11 REST API powering the Pathshalaa educational platform.

## Branches

| Branch | Purpose |
|--------|---------|
| `stag` | Staging (pre-production) â€” mirrors production |
| `stag.beta` | Active development branch â€” merged into `stag` after review |

---

## Requirements

- PHP >= 8.2
- Composer
- MySQL 8.x
- Node.js >= 18 (for frontend asset compilation)

---

## Installation

```bash
git clone <repo-url>
cd pathshalaa_api
composer install
cp .env.example .env
php artisan key:generate
```

Configure your `.env` file with the correct `DB_*`, `JWT_SECRET`, `FIREBASE_*`, and `OPENAI_API_KEY` values.

---

## Deployment Steps (Staging / Production)

> Run these steps in order after pulling new code from `stag`.

```bash
# 1. Pull latest code
git pull origin stag

# 2. Install/update PHP dependencies
composer install --no-dev --optimize-autoloader

# 3. Run database migrations
php artisan migrate --force

# 4. Clear application caches
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

# 5. Re-cache for production performance
php artisan config:cache
php artisan route:cache
php artisan view:cache

# 6. Restart queue workers (if using queues)
php artisan queue:restart
```

> **Note:** All database schema changes are now managed via Laravel migrations.
> Never apply raw SQL directly to the database â€” always create a migration file instead.

---

## Database Migrations

All schema changes are version-controlled as Laravel migration files in `database/migrations/`.

To apply all pending migrations:

```bash
php artisan migrate
```

To roll back the last batch:

```bash
php artisan migrate:rollback
```

To check migration status:

```bash
php artisan migrate:status
```

### Migration History Summary

| Date | Migration | Tables Affected |
|------|-----------|----------------|
| Oct 2024 | `2024_10_03_*` | `stu_testseries_analysis` |
| Oct 2024 | `2024_10_08_*` | `users` |
| Oct 2024 | `2024_10_14_*` | `firm_detail` (create) |
| Oct 2024 | `2024_10_30_*` | `topics`, `topicsubscriptions`, `notifications` |
| Nov 2024 | `2024_11_09_*` | `dashboard_sections` (create) |
| Nov 2024 | `2024_11_11_*` | `app_top_category_by_class` (create) |
| Nov 2024 | `2024_11_20_*` | `sliders`, `testresult`, `schools`, `users` |
| Nov 2024 | `2024_11_23_*` | `testseries` |
| Nov 2024 | `2024_11_25_*` | `notifications` |
| Dec 2024 | `2024_12_18_*` | `testseries` |
| Dec 2024 | `2024_12_23_*` | `users`, `stu_testseries_analysis` |
| Dec 2024 | `2024_12_30_*` | `testseries` |
| Jan 2025 | `2025_01_01_*` | `users` |
| Jan 2025 | `2025_01_08_*` | `users` |
| Jan 2025 | `2025_01_29_*` | `payments` |
| Apr 2025 | `2025_04_04_*` | `users` |
| Apr 2025 | `2025_04_21_*` | `testseries` |
| Jun 2025 | `2025_06_23_*` | `testseries` |
| Oct 2025 | `2025_10_07_*` | `coin_transactions` (create), `users` |
| Nov 2025 | `2025_11_12_*` | `groups`, `group_users`, `group_test_series`, `group_activity_log`, `question_translations` |
| Nov 2025 | `2025_11_13_*` | `testseries`, `groups` |
| Nov 2025 | `2025_11_14_*` | `testseries`, `jobs`, `failed_jobs`, `job_batches`, `scheduled_notifications`, `syllabi`, `syllabus_topics` |
| Nov 2025 | `2025_11_24_*` | `questions` (InnoDB conversion, foreign keys) |
| Dec 2025 | `2025_12_04_*` | `questions`, `testseries` |
| Dec 2025 | `2025_12_05_*` | `pending_enrollments` (create) |
| Dec 2025 | `2025_12_20_*` | `testseries` |
| Dec 2025 | `2025_12_26_*` | `lk_category` |
| Dec 2025 | `2025_12_27_*` | `groups` |
| Jan 2026 | `2026_01_17_*` | `group_test_series` |
| Jan 2026 | `2026_01_27_*` | `enroll_testseries` (merge from `group_test_series`) |
| Jan 2026 | `2026_01_28_*` | `sessions` (create) |
| Feb 2026 | `2026_02_03_*` | `ai_question_batches` |
| Feb 2026 | `2026_02_12_*` | `syllabi` |
| Feb 2026 | `2026_02_19_*` | `users` |
| Feb 2026 | `2026_02_23_*` | `feature_plan` (create) |

---

## Required Packages

```bash
composer require barryvdh/laravel-dompdf
composer require barryvdh/laravel-snappy
composer require mpdf/mpdf
composer require kreait/firebase-php
composer require darkaonline/l5-swagger
composer require phpoffice/phpword
```

---

## Environment Variables

Key `.env` variables required:

```env
APP_KEY=
APP_URL=

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pathshalaa
DB_USERNAME=root
DB_PASSWORD=

JWT_SECRET=

OPENAI_API_KEY=
OPENAI_API_URL=https://api.openai.com/v1/chat/completions
OPENAI_MODEL=gpt-4o-mini
OPENAI_MAX_RETRIES=3
OPENAI_RETRY_DELAY=2
OPENAI_TIMEOUT=60
OPENAI_MAX_TOKENS=2000
OPENAI_TEMPERATURE=0.7

L5_SWAGGER_GENERATE_ALWAYS=true

BROWSERSHOT_CHROME_PATH=/path/to/chrome
```

---

## Swagger API Documentation

```bash
# Install Swagger
composer require darkaonline/l5-swagger
php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"

# Generate/refresh docs
php artisan l5-swagger:generate
```

API docs available at: `/api/documentation`

---

## Cron / Queue

Add the following cron entry to publish scheduled test results automatically:

```cron
* * * * * php /path/to/project/artisan schedule:run >> /dev/null 2>&1
```

Start queue worker:

```bash
php artisan queue:work --queue=default --tries=3
```

---

## Merging stag.beta into stag

```bash
# On local machine
git checkout stag
git pull origin stag
git merge stag.beta
git push origin stag
```

Then run the deployment steps on the server (see above).

---

## Contributing & Development Guidelines

- All database schema changes **must** be created as Laravel migration files.
- Never apply raw SQL directly to staging or production databases.
- Use `Schema::hasColumn()` / `Schema::hasTable()` guards in migrations for idempotency.
- Follow PSR-12 coding standards.
- Tag releases following semantic versioning.

