class Post extends Model { protected $table = 'posts'; protected $fillable = ['title', 'body']; public function user() { return $this->belongsTo(User::class); } }
class Post_model extends CI_Model { public function __construct() { parent::__construct(); $this->load->database(); } public function get_posts() { $query = $this->db->get('posts'); return $query->result(); } public function insert_post($data) { return $this->db->insert('posts', $data); } }These examples demonstrate how Models are used to interact with databases in PHP frameworks. Package libraries that employ models include Laravel, CodeIgniter, and Yii.