NEAMAT
Notes from the terminal

Blog

Practical Laravel & PHP

Latest Articles

Short, practical write-ups from real backend work — click any post to read.

Laravel4 min read
5 Ways to Speed Up Slow Laravel Queries

Eager loading, indexing, and chunking — the habits that keep an Eloquent-heavy app fast as your data grows.

REST API5 min read
Securing REST APIs with Laravel Sanctum

A practical walkthrough of token-based authentication for SPAs and mobile clients without the overhead of OAuth.

Database4 min read
Designing a Database Schema for a POS System

Lessons from building an inventory-and-sales system: normalization trade-offs and where denormalizing pays off.

Maintenance3 min read
A Checklist for Inheriting Someone Else's Laravel App

What to check first when you take over an existing codebase — before you touch a single line.

Payments4 min read
Handling Payment Webhooks the Safe Way

Idempotency, signature verification, and logging — the details that prevent double-charging a customer.

Deployment3 min read
Deploying Laravel on Shared Hosting with cPanel

A no-nonsense guide to getting a Laravel app running smoothly on budget-friendly shared hosting.

Slow queries are the most common reason a Laravel app feels sluggish under real traffic. Here are five habits that consistently help:

  1. Eager load relationships. Replace $order->items inside a loop with Order::with('items')->get() to avoid N+1 queries.
  2. Index what you filter and sort by. If a column shows up in a WHERE or ORDER BY clause often, it probably needs an index.
  3. Select only what you need. select('id','name') instead of select('*') reduces memory and transfer time on wide tables.
  4. Chunk large exports. Use chunk() or cursor() when processing thousands of rows so you don't exhaust memory.
  5. Cache expensive, rarely-changing queries. Laravel's cache layer (Redis or file) can turn a 400ms report query into a 2ms cache hit.

None of these require exotic tooling — just discipline applied consistently across the codebase.

For most single-page apps and mobile clients talking to a Laravel backend, full OAuth2 is overkill. Laravel Sanctum offers a lighter path:

The result: production-grade token authentication without wiring up a full OAuth server.

A POS system's schema has to handle rapid writes (sales) and rich reads (reports) at the same time. A few lessons from building one:

Small decisions like these save painful migrations six months into production.

Taking over someone else's Laravel project is common freelance work. Before writing any code, I check:

  1. Environment parity — can I run it locally with the same PHP/MySQL versions as production?
  2. Test coverage — are there any automated tests I can lean on, even partial ones?
  3. Queued jobs and scheduled tasks — what's running in the background that isn't obvious from the routes file?
  4. Third-party API keys — which external services does this app depend on, and are the credentials still valid?
  5. Migration history — does the schema in the database actually match what the migration files say?

A day spent mapping the terrain saves a week of surprises later.

Payment webhooks look simple until money starts disappearing or doubling. A few non-negotiables:

These four habits prevent the vast majority of payment-related support tickets.

Not every client needs a Forge-managed VPS. Shared hosting with cPanel still works well for smaller Laravel apps:

  1. Point the domain's document root at public/, not the project root — this is the step people miss most often.
  2. Set environment variables through cPanel's PHP settings or a carefully permissioned .env file.
  3. Run composer install --no-dev --optimize-autoloader before uploading, since Composer often isn't available on the host itself.
  4. Cache config and routes (artisan config:cache, route:cache) to offset the lack of OPcache tuning access.
  5. Use a cron job pointed at artisan schedule:run for anything that needs to run on a timer.

It's not glamorous, but it's reliable — and often exactly what a budget-conscious client needs.

Have a backend challenge to solve?

I write about what I build — and I'm happy to help you build yours.

Get In Touch