Database Integration
Models
Creating a Model
<?php
namespace App\Models;
use System\Core\BaseModel;
class UsersModel extends BaseModel {
protected $table = 'users'; // Connects to the 'users' table
protected $fillable = ['username', 'email']; // Columns that can be changed
protected $guarded = ['id', 'created_at']; // Columns that should NOT be modified
public function _schema() {
return [
'id' => ['type' => 'int unsigned', 'auto_increment' => true, 'key' => 'primary'],
'username' => ['type' => 'varchar(100)', 'null' => false],
'email' => ['type' => 'varchar(150)', 'null' => false]
];
}
public function getUsers($where = '', $params = [], $orderBy = 'id DESC', $page = 1, $limit = null){
return $this->list($this->table, $where, $params, $orderBy, $page, $limit);
}
// Additional methods for custom queries
}Changing the Database Driver
Using a Model in a Controller
Managing Database Schema
Last updated
Was this helpful?