What is a Model in CodeIgniter 4?

Answer

CodeIgniter 4 ships with a powerful Model class that provides a rich set of database interaction methods. Extend CodeIgniter\Model and configure the model with properties: protected $table = "users", protected $primaryKey = "id", protected $allowedFields = ["name", "email", "password"], protected $useTimestamps = true. The model provides: find($id), findAll(), where("active", 1)->findAll(), insert($data), update($id, $data), delete($id). It also has built-in validation via the $validationRules property and business rule callbacks (beforeInsert, afterFind, etc.). CI4 models are lighter than Laravel's Eloquent but sufficient for most use cases.