Skip to main content

Overview

The Teacher model manages teacher-specific operations including creation, retrieval, and deletion. File: app/models/Teacher.php

Methods

all

Retrieves all teachers with their user information. SQL Query:
SELECT users.id, users.name, users.email
FROM teachers
JOIN users ON teachers.id = users.id
result
array
Returns array of all teacher records
Example:
$teacher = new Teacher();
$allTeachers = $teacher->all();

create

Creates a new teacher record in both users and teachers tables.
name
string
required
Teacher’s full name
email
string
required
Teacher’s email address
password
string
required
Plain text password (will be hashed)
SQL Queries:
-- 1. Insert into users table
INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, 'teacher')

-- 2. Insert into teachers table
INSERT INTO teachers (id) VALUES (?)
result
void
No return value (throws exception on failure)
Example:
$teacher = new Teacher();
$teacher->create('Dr. Smith', 'smith@example.com', 'securepass123');
The password is automatically hashed using PHP’s password_hash() with PASSWORD_DEFAULT algorithm.

delete

Deletes a teacher record (cascades to teachers table via foreign key).
id
int
required
Teacher ID to delete
SQL Query:
DELETE FROM users WHERE id = ?
result
void
No return value (throws exception on failure)
Example:
$teacher = new Teacher();
$teacher->delete(3);
This operation deletes the user from the users table. The teachers table record is deleted automatically via CASCADE.

Build docs developers (and LLMs) love