# Porting notes: plain PHP → Laravel 12

## Where things went

| Plain PHP | Laravel |
|---|---|
| `app/bootstrap.php` (env, db, helpers) | `config/shop.php`, Eloquent models, `app/Support/Text.php`, `app/Support/Settings.php`, `app/helpers.php` |
| `migrate()` + `ensure_schema()` | `database/migrations/2026_11_23_000000_create_store_schema.php` (adopts existing tables) and `..._000001_upgrade_store_data.php` (roles, slugs, legacy specs) |
| `bin/setup.php` | `php artisan shop:setup` (`app/Console/Commands/ShopSetup.php`) |
| `app/rbac.php` | `app/Support/Permissions.php`, `Role` and `User` models (`$user->can('orders.view')`) |
| `app/catalog.php` | `app/Services/Catalog.php` |
| `app/orders.php` | `app/Services/OrderService.php`, `app/Services/Paystack.php` |
| `app/notify.php` | `app/Services/Notifier.php` (Laravel Mail + HTTP client) |
| `app/jobs.php` | `app/Services/JobService.php`, `TechnicianLinkController`, `Api/JobController` |
| `app/careers.php` (public form) | `CareersController`, `resources/views/storefront/careers.blade.php` |
| `app/api.php` | `routes/api.php`, `app/Http/Controllers/Api/*`, `PaystackController` |
| `app/product_page.php` | `StorefrontController`, `resources/views/storefront/*.blade.php` |
| `public/index.php` router | `routes/web.php`, `routes/api.php` |
| `app/admin.php`, `admin_more.php`, `admin_jobs.php`, careers admin | `routes/admin.php`, `app/Http/Controllers/Admin/*`, `resources/views/admin/*` |
| `analytics.php` | `app/Services/Analytics.php`, `app/Support/Charts.php` (server-side SVG), `app/Support/Csv.php` |
| `admin_user()`, `need()`, `can()` | Laravel `Auth` (session guard on the existing `users` table) + `Gate::before` reading the role's permissions; `AdminAuth` middleware; `@can` in views |
| `audit()` | `App\Support\Audit::log()` |
| `save_image()` | `App\Support\ImageStore` (same checks: real JPG/PNG/WebP, 3 MB, random name) |
| `public/store.html` | `resources/storefront/store.html` (served at `/`, unchanged) |
| `rate_limits` table | Laravel `RateLimiter` (file cache): same buckets and limits. The old table is kept but no longer used. |
| `csrf_check()` | Laravel CSRF (`@csrf` on the careers and technician forms) |
| `secure_headers()` | `app/Http/Middleware/SecurityHeaders.php` |

## Phase 1 (done)
- Storefront JSON API with the same paths, status codes and error messages, so `store.html` works without changes
- Checkout with server-side pricing, stock reservation (conditional decrement), Paystack start, verify, webhook, callback and retry, bank transfer, pay on delivery and WhatsApp
- Product pages, new arrivals, sitemap, robots, JSON-LD, share buttons
- Reviews with the verified-purchase tag; inquiries
- Technician requests (on their own or at checkout), tracking, the private technician link, the careers form
- Email and SMS (Termii, Twilio), admin alerts
- Job assignment logic (`JobService::assign`, `techniciansFor`), ready for the admin screens
- `shop:setup`, feature tests

## Phase 2 (done)
- Admin login with Laravel's session guard: the same bcrypt passwords, 5 failed tries per 15 minutes, session renewed at login, disabled accounts thrown out on their next click, temporary passwords must be changed first
- Every admin screen at the same URL: dashboard, reports and CSV exports, orders (confirm payment, status, cancel returns stock once), products (photos, gallery order, spec fields, cost price only with "Costs & margins"), inventory, reviews, categories and spec fields, services, delivery fees, inquiries, settings, account, staff, roles, audit log, technician jobs, technicians, applications
- The same 21 permissions and 9 default roles; stored custom roles keep working
- Feature tests for the admin (`tests/Feature/AdminTest.php`, `AdminJobsTest.php`)

## Small differences to know about
- Rate limits use a fixed one-hour window that starts at the first attempt. The old version used a sliding window. The limits themselves are unchanged.
- The old code saved timestamps with `date()` in `APP_TIMEZONE`. Laravel does the same once `APP_TIMEZONE=Africa/Lagos` is set in `.env`, so keep that setting.
- Odd JSON input, such as an array where a name should be, is treated as empty instead of causing a PHP warning.
- Admin sessions use Laravel's session cookie, so everyone signs in again once after the switch.
- Category, service and delivery-fee changes and deletions are now written to the audit log too.
- Admin forms post to the same URLs, but Laravel's CSRF token replaces the old `_csrf` field. Old admin pages left open in a browser tab need a refresh after the switch.
