All work / Personal
Pharmacy API Laravel REST API with Passport token authentication
The Laravel 11 API behind the dashboard: catalogue, orders, prescriptions, coupons, loyalty points, messages and token authentication, plus the endpoints customers use.
What it serves
One API for two kinds of user. Admins manage the catalogue, coupons, customer messages and sales analytics; customers sign up, browse products and save favourites, upload prescriptions, place orders and register a device token for push notifications. The data model has 17 Eloquent models, from products, brands and categories to orders and their items, prescriptions, coupons, points transfers, ratings, locations and notifications.
Authentication
Laravel Passport issues two tokens at sign-up: an access token with a user-access-token scope, and a refresh token with its own scope that expires after 30 days. A middleware rejects any request whose token lacks the access scope, so a refresh token is good for one thing only: getting a new access token. Admin routes sit behind a second middleware that checks the user’s role, and new accounts confirm themselves with a six-digit one-time code.
How the code is organised
Controllers stay thin. Shared logic lives in traits for authentication, creating and updating records, and list queries, and every response goes through one helper, so clients always get the same shape: message, data, token and errors. Input is validated with form requests, list endpoints share the same filtering, sorting and take/skip pagination, and factories and seeders fill a development database.