We build Laravel backends for mobile apps—not a "cheap" choice, but a pragmatic one. When you already have a PHP team, or when you need a working API with authentication, push notifications, file storage, and queues in 4–6 weeks, Laravel Sanctum + Eloquent + Horizon covers 90% of the tasks without extra infrastructure. Our experience: 5+ years and 30+ projects, with a guarantee of code quality and security.
Why Laravel for Mobile Backend?
Laravel provides ready-made solutions for typical mobile backend tasks: authentication, queues, caching, REST API. This cuts development time and simplifies maintenance. We don't just use the defaults—we apply optimizations for high loads.
Common Mistakes in Laravel Backend
Eloquent N+1 kills mobile API. User::all() with ->posts inside a foreach is classic. With 30 items you get 31 queries, response time 600ms instead of 20ms. The mobile client waits, then retries, then a bad store review. Fix: with(['posts']) on load, ->load() if already loaded. We diagnose with Laravel Debugbar or Telescope counting duplicate queries.
Queues without supervisor. Mail::send() or FCM push in an HTTP handler—the request hangs until Firebase responds. If APNs lags (it happens), the mobile client gets a 30-second timeout. All async operations go into dispatch(new SendPushJob($payload)) with Laravel Horizon for monitoring Redis queues.
How We Build a Laravel Backend for Mobile
Authentication: Laravel Sanctum for SPA/mobile token-based auth. Tokens are stored in the personal_access_tokens table; on login we issue an access + refresh pair. Sanctum doesn't handle refresh rotation out of the box—we implement it via a custom RefreshTokenController that invalidates the old token in the database.
For OAuth via social networks: Laravel Socialite with Google, Facebook, Apple drivers. Apple Sign In requires extra care: nonce is validated in id_token, and the email Apple provides only on first login—we save it immediately.
Push notifications: packages laravel-notification-channels/fcm for FCM and laravel-notification-channels/apn for APNs. Notifications go via Laravel Notifications API ($user->notify(new OrderStatusChanged($order))), the channel is selected by via().
How We Optimize Eloquent Queries
Real case: a 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–800ms depending on filters. After optimization: raw query via DB::select() for complex selection + Cache::remember() for 60 seconds on popular filters—p95 dropped to 40ms. The mobile client stopped showing the skeleton loader.
| Query Type | Response Time (p95) | SQL Queries |
|---|---|---|
Eloquent without with() |
600 ms | 31 |
Eloquent with with() |
120 ms | 2 |
| Raw query + Cache | 40 ms | 1 (or 0 from cache) |
API Project Structure
app/ ├── Http/Controllers/Api/V1/ — versioned controllers ├── Http/Resources/ — API Resources for response formatting ├── Http/Requests/ — Form Request validation ├── Models/ — Eloquent models ├── Jobs/ — async tasks (pushes, emails, webhooks) └── Notifications/ — Laravel Notifications routes/api.php — routes with `sanctum` middleware Using API Resources instead of ->toArray() directly is important. Resources control response fields, load related relationships via whenLoaded() without risking N+1, and the response structure doesn't change unexpectedly when the model changes.
How to Set Up Laravel for Push Notifications
- Install package
laravel-notification-channels/fcm. - Create notification class
app/Notifications/PushNotification.php. - Define
via()method—return['fcm']. - In
toFcm()return anFcmMessageinstance with title and body. - Send:
$user->notify(new PushNotification($data)).
Deployment
Laravel Octane (Swoole or RoadRunner) gives a 3–5x throughput boost over PHP-FPM—relevant if your budget doesn't allow horizontal scaling. On Swoole, note: static class properties persist across requests, ServiceProvider is not re-created—you must 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 a web interface for monitoring workers and Redis queue metrics.
What's Included
- API architecture design
- RESTful endpoints with versioning
- Authentication (Sanctum/Passport) and OAuth2
- Push notifications (FCM, APNs)
- Queues and background jobs (Jobs, Horizon)
- Query optimization (Eager Loading, Cache)
- Documentation (Scribe/OpenAPI)
- Deployment and monitoring
- Team training (2–3 sessions)
Timelines and Cost
Timelines: API with 12–18 endpoints — 3–5 weeks. Complex marketplace — 8–12 weeks. Cost is calculated individually based on scope. We'll evaluate your project for free—contact us.
Additional Details
We use Continuous Integration (GitLab CI/GitHub Actions) for automated testing and deployment. Code is covered with unit tests (PHPUnit) and integration tests for critical scenarios.Order turnkey development—get a reliable backend that won't let you down under peak load. Reach out for a consultation.







