Dynamic Database Tables & Validation

Hotspot Manager uses dynamic database tables for customer records, allowing each dealer to have their own isolated customer table. Instead of a single customers table, the system creates tables in the format dealer_{dealerId}_customers (e.g., dealer_42_customers).

HasDynamicTable Trait

The HasDynamicTable trait is used on models to enable dynamic table resolution based on the dealer context. This ensures data separation and scalability across multiple dealers.

Validation for Dynamic Tables

Standard Laravel validation rules like exists:customers,id do not work with dynamic tables, since the base customers table does not exist. To solve this, custom validation logic is implemented:

  • Methods like Customer::findCustomerInDynamicTables() are used to search for records across all dealer-specific customer tables.
  • Custom validators replace the default exists and unique rules for customer-related fields.
  • This approach prevents validation errors and ensures accurate lookups regardless of dealer.

Note: When writing code or queries for customer data, always use the provided dynamic table helpers and avoid referencing a global customers table.