PHP (Laravel) Backend Development for Mobile Applications
Laravel is not a "cheap" choice, but pragmatic. When client already has PHP team, or when you need working API with authentication, push notifications, file storage and queues in 4–6 weeks — Laravel Sanctum + Eloquent + Horizon cover 90% of tasks without extra infrastructure.
What Usually Goes Wrong
Eloquent N+1 kills mobile API. User::all() with ->posts inside foreach — classic. On 30-element collection, 31 SQL queries, response 600 ms instead of 20 ms. Mobile client waits, then retry, then app store complaint. Fix — with(['posts']) on load, ->load() if already loaded. Diagnose via Laravel Debugbar or Telescope with duplicate query counts.
Queues without supervisor. Mail::send() or FCM push in HTTP handler — request hangs while Firebase responds. If APNs lags (happens), mobile client gets 30-second timeout. All async operations — into dispatch(new SendPushJob($payload)) with Laravel Horizon for Redis queue monitoring.
Building Laravel Backend for Mobile
Authentication — Laravel Sanctum for SPA/mobile token-based auth. Tokens stored in personal_access_tokens table, login issues access + refresh pair. Sanctum doesn't do refresh rotation by default — implement via custom RefreshTokenController with old token invalidation in DB.
OAuth via social networks — Laravel Socialite with Google, Facebook, Apple drivers. Apple Sign In requires care: nonce validated in id_token, and email Apple provides only on first login — save immediately.
Push notifications: package laravel-notification-channels/fcm for FCM and laravel-notification-channels/apn for APNs. Notifications via Laravel Notifications API ($user->notify(new OrderStatusChanged($order))), channel selected by via() method.
Real case: marketplace for iOS/Android, ~25,000 DAU. REST API on Laravel 10, PostgreSQL, Redis for sessions and cache. Product catalog endpoint (/api/v1/products) with filters and pagination. First version — Eloquent with ->paginate(20), response time 350–800 ms depending on filters. After optimization: raw query via DB::select() for complex selection + Cache::remember() for 60 seconds on popular filters — p95 became 40 ms. Mobile client stopped showing skeleton loader.
API Project Structure
app/
├── Http/Controllers/Api/V1/ — controllers with versioning
├── Http/Resources/ — API Resources for response formatting
├── Http/Requests/ — Form Request validation
├── Models/ — Eloquent models
├── Jobs/ — async tasks (pushes, mail, webhooks)
└── Notifications/ — Laravel Notifications
routes/api.php — routes with `sanctum` middleware
API Resources instead of ->toArray() directly — important. Resource controls response fields, nested relationships load via whenLoaded() without N+1 risk, and response structure doesn't unexpectedly change with model changes.
Deployment
Laravel Octane (Swoole or RoadRunner) gives 3–5x throughput gain over PHP-FPM — relevant if budget doesn't allow horizontal scaling. With Swoole, remember: static class properties live between requests, ServiceProvider doesn't recreate — explicitly reset state via octane:table or avoid stateful services.
Supervisor for queues: php artisan queue:work --queue=high,default --sleep=3 --tries=3. Laravel Horizon provides web interface for worker monitoring and Redis queue metrics.
Timeline: API with 12–18 endpoints, authentication, pushes, S3 storage — 3–5 weeks. Complex marketplace with sellers, payments and analytics — 8–12 weeks.







