Apex Models

Apex provides a clean, straight forward models implementation. In essence, you write the SQL database schema, and Apex will generate the necessary PHP model classes based on the database tables.

The model classes generated will include all properties utilizing constructor property promotion, taking into account column type, default value, nullable, et al. All foreign keys will also be evaluated with the necessary methods generated to retrieve any parent / child objects.

Static Methods

  • public static all() - Get all records from the database table.
  • public static count() - Get the number of records within the database table with optional where clause.
  • public static deleteMany() - Delete multiple records from the database table.
  • public static insert() - Insert a new record into the database table.
  • public static insertOrUpdate() - Insert or update a record within the database table.
  • public static purge() - Purge and delete all records within the database table.
  • public static update() - Update multiple records within the database table.
  • public static where() - Select multiple records from the database table.
  • public static whereFirst() - Get a model instance of the first record found for a given where clause.
  • public static whereId() - Select a single model instance based on the value of the primary key / id column.



Non-Static Methods

  • public delete() - Delete a single model instance from the database table.
  • public getChildren() - Get child records based on a foreign key constraint.
  • public save() - Save and update an individual model instance.
  • public toArray() - Get all properties of the model instance returned in an array.