Repository navigation
API Model
Caligrafy Quill 2.26.0. Generated from the source by
php qa/build-api-reference.php; the guides explain how to use these classes, this reference says exactly what each public method takes and returns. Back to the API reference.
Part of Data.
namespace Caligrafy;
class Model extends \stdClassSource: framework/core/Model.php:20
Class Model is the base model from which the application models can be extended
public $table-
public static $strictRelations = null: Lazy loading of relations (2.26.0). A model the query builder read among several rows (Book::where(...)->get(), paginate(), chunk()) that runs a relation method (hasOne, hasMany, belongsTo, belongsToMany) would run one query per row (N+1): in development that throws [ERROR 2004]; in production (or with STRICT_RELATIONS=false) it logs a warning once per request and relation. $book->lazy()->author() allows one call, #[Caligrafy\Lazy] on the relation method allows it always. A model read alone (find(), first(), the instance find() and all()) is not guarded.
->__construct()->__invoke()->associate()->create()->update()->delete()->__call()Model::__callStatic()->all()->search()->save()->hasOne()->hasMany()->belongsTo()->belongsToMany()->attach()->detach()->lazy()Model::collected()Model::strictRelations()Model::forgetLazyWarnings()->arrayToModel()->toArray()->tableExists()
public function __construct($table = null)No doc comment.
Parameters
-
$table, defaultnull
Source: framework/core/Model.php:47
public function __invoke($table = null, $dynamicArgs = array())No doc comment.
Parameters
-
$table, defaultnull -
$dynamicArgs, defaultarray()
Source: framework/core/Model.php:52
public function associate($table)Associates a model with a table in the database
Parameters
$table
Source: framework/core/Model.php:66
public function create($inputs)Basic CRUD functions on the associated table
Parameters
$inputs
Source: framework/core/Model.php:77
public function update($inputs, $id)No doc comment.
Parameters
$inputs$id
Source: framework/core/Model.php:99
public function delete($id)No doc comment.
Parameters
$id
Source: framework/core/Model.php:117
public function __call($method, $args)$book->find($id) (instance: SELECT * FROM <its table> WHERE id = ?, as before) and $book->where(...) etc.
Parameters
$method$args
Source: framework/core/Model.php:150
public static function __callStatic($method, $args)Book::query(), Book::find($id), Book::where(...), Book::with(...), Book::paginate(20)...
Parameters
$method$args
Source: framework/core/Model.php:166
public function all($args = array())Fetches all the records, optionally completed by SQL clauses
Parameters
-
$argsarray, defaultarray(): 'condition' (ex: 'WHERE price > ?'), 'order' (ex: 'ORDER BY title'), 'limit' (ex: 'LIMIT 10') and 'bindings' (array of values bound to the ? placeholders). The clauses are inserted as is: never concatenate user input in them, use ? placeholders and 'bindings' instead.
Source: framework/core/Model.php:198
public function search($scope, $keywords)Search functionality that searched records in a table
Parameters
-
$scopestring: defines the columns to search in the database separated by commas -
$keywordsstring: defines the LIKE pattern to look for (% and _ are wildcards). It is bound, never inlined.
Returns array: $result results found in the database
Source: framework/core/Model.php:227
public function save()Save functionality applied directly to the object that could update or create depending on whether the object has an id or not
Source: framework/core/Model.php:307
public function hasOne(
$modelName,
$joinedTableName,
$foreignKey = null,
$localKey = null,
$functionName = null
)Defines the hasOne relationship
Parameters
-
$modelNamestring: defines the name of the model to join to -
$joinedTableNamestring: defines the name of the table to join to -
$foreignKeystring, defaultnull: defines the identifier key of the key indexing the joined table -
$localKeystring, defaultnull: defines the identifier key of the joined table -
$functionName, defaultnull
Returns Model: object containing the records from the join
Source: framework/core/Model.php:324
public function hasMany(
$modelName,
$joinedTableName,
$foreignKey = null,
$localKey = null,
$functionName = null
)Defines the hasMany relationship
Parameters
-
$modelNamestring: defines the name of the model to join to -
$joinedTableNamestring: defines the name of the table to join to -
$foreignKeystring, defaultnull: defines the identifier key of the key indexing the joined table -
$localKeystring, defaultnull: defines the identifier key of the joined table -
$functionName, defaultnull
Returns Model: object containing the records from the join
Source: framework/core/Model.php:355
public function belongsTo($modelName, $joinedTableName, $foreignKey = null, $localKey = null)No doc comment.
Parameters
$modelName$joinedTableName-
$foreignKey, defaultnull -
$localKey, defaultnull
Source: framework/core/Model.php:378
public function belongsToMany(
$modelName,
$joinedTableName,
$foreignKeyLocal = null,
$foreignKeyJoin = null,
$functionName = null
)No doc comment.
Parameters
$modelName$joinedTableName-
$foreignKeyLocal, defaultnull -
$foreignKeyJoin, defaultnull -
$functionName, defaultnull
Source: framework/core/Model.php:385
public function attach($joinedTableName, $id)No doc comment.
Parameters
$joinedTableName$id
Source: framework/core/Model.php:452
public function detach($joinedTableName, $id)No doc comment.
Parameters
$joinedTableName$id
Source: framework/core/Model.php:458
public function lazy()Allows the next relation call of this model to load lazily, once: $book->lazy()->author() (a relation read on purpose for one of several rows)
Returns $this
Source: framework/core/Model.php:499
public static function collected(array $models, array $loaded = array())Marks the models a query read together (Query::get() with more than one row): their relation methods are then guarded against lazy loading. Called by the query builder.
Parameters
-
$modelsarray: the models of one result -
$loadedarray, defaultarray(): the relations the query loaded with with()
Source: framework/core/Model.php:512
public static function strictRelations()Whether a lazy relation call throws: false in production (APP_ENV=production) and with STRICT_RELATIONS=false, true otherwise. Decided once; Model::$strictRelations = true|false forces it, null decides again.
Source: framework/core/Model.php:526
public static function forgetLazyWarnings()Forgets the lazy loading warnings given so far (a new request: Query::forgetShapes() calls it)
Source: framework/core/Model.php:539
public function arrayToModel($array)Turns an array into a Model
Parameters
-
$arrayarray: takes the array that needs to be converted to a model
Returns Model: object containing the modified object
Source: framework/core/Model.php:613
public function toArray()Turns Model into an array
Returns array: representation of the model
Source: framework/core/Model.php:628
public function tableExists($tablename)Checks if a table exists
Parameters
$tablename
Returns boolean: of the result
Source: framework/core/Model.php:668
Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.
Why Caligrafy: the benefits, the measurements, and what it is not yet
-
Quickstart with Claude: describe it, approve it, ship it
or the Quickstart: the same three steps by hand, in 5 minutes
- How Caligrafy works: the ideas in 5 minutes
- Your first capability: build a feature, page included
-
Capabilities in depth
-
#[Capability]: every option - Scheduled jobs: capabilities on a timer
- Notifications: web push and email
- Background jobs: capabilities run later
- Migrations: database changes, in order
- The cache
-
Testing your app
- Dependency injection
- Validation rules
-
Web pages
- Views and page components
- Design styles: another look, one setting
- Declarative routes: every request, in one line
-
Route::page·Route::form·Route::auth·Route::webhook·Route::download·Route::redirect·Route::action·Route::snap· capability routes - How to export a list as CSV
- Controllers: moving one to a declared route · how to, step by step
- Forms and helpers
-
Vue apps
-
Mobile and tablet
-
REST API
-
AI agents
-
Snap Cards and the assistant
- Payments: Stripe and crypto
- Face detection and face login
- OpenAI: chat and images · Assistants
- Open models: Llama, Mistral...
- Chatbots with Watson
- Machine learning in the browser
- Metadata and social cards · search and analytics
-
Putting it online: the production image, the database at every start
-
API reference: every class and method
-
Routing ·
Route·AuthRoutes· pages ·Controller· capabilities -
Data ·
Model·Query· sign-in · jobs ·Notify· payments · AI -
Interfaces · Snap ·
Snap\Cards·Snap\Conversation· testing · tooling · helper functions
-
Routing ·
-
Caligrafer: every command
- Project · build · data · agents · jobs and tests · maintenance · deploy
- Installation, configuration and Caligrafer
- Routing · Request · Controllers · Views
- Vue: flow of information · routes · validations
- Security and upgrading
- Release notes: 2.26 · 2.25 · 2.24 · 2.23 · 2.22 · 2.21 · 2.20 · 2.19 · 2.18 · 2.17 · 2.16 · 2.15 · 2.14 · 2.13 · 2.12 · 2.11 · 2.10 · 2.9 · 2.8 · 2.7 · 2.6 · 2.5 · 2.4 · 2.3 · 2.1 · October 2026 · changelog
- Testing Caligrafy (contributors)