Knowledgebase

Database and Eloquent: Everything That Matters, Briefly Print

  • phplaravel, database, cpanel, migration, troubleshooting, performance, permissions, guide
  • 0

The summary.

ON CPANEL, DATABASE AND USER NAMES ARE PREFIXED WITH YOUR ACCOUNT NAME

Configuration referring to unprefixed names fails with access denied. Use the full names shown in cPanel.

NEVER MODIFY A MIGRATION THAT HAS ALREADY RUN IN PRODUCTION

Write a new one. And always back up before migrating.

NEVER PERMIT EVERY FIELD TO BE FILLED FROM INPUT

Bulk assignment without restriction lets submitted data set any column, including ones determining permissions.

Name the fields you accept explicitly.

THE COMMONEST PERFORMANCE FAULT IN LARAVEL APPLICATIONS

Accessing a relationship inside a loop, which issues one query per record.

It works perfectly with three records in development and collapses in production. Load relationships in advance, and watch the query count.

USE EXACT DECIMAL TYPES FOR MONEY

Floating point cannot represent some values exactly.

INDEX WHAT YOU FILTER, SORT AND JOIN BY

Without an index the database examines every row.

WRAP RELATED CHANGES IN A TRANSACTION

But keep external calls outside it — a transaction holds locks, and holding them during a network call is harmful.

NEVER USE REAL CUSTOMER DATA IN DEVELOPMENT

Anonymise it first.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot