Table User Model Class SELECT * FROM user WHERE id = 100; INSERT INTO user VALUES(‘taro’); Read: User::find(100); Create: $user-‐>save(); UPDATE user SET name = ‘kotaro’ WHERE id = 100; Update: $user-‐>save(); DELETE user WHERE id = 100; Delete: $user-‐>destroy();
Table User Model Class Delete: $user-‐>destroy(); User Controller Class delete-K Rou�ng / Dispacher Public func�on delete() { $id = $_GET[‘$id’]; $user = User::find($id); $user.destroy(); }
Model Class SELECT count(*) as count FROM user; SELECT count(*) as count FROM user WHERE mail = $user-‐>mail; count: User::count(); Unique check: $user-‐>isUniqueMail(); // return boolean value name include in password: $user = new User(); $user-‐>name = ‘hoge’; $user-‐>password = ‘hogehoge’ $user-‐>isIncludedNameInPassword(); // return boolean value
User Model Class Public func�on show() { $user = User::findByEmail(‘[email protected]’); $addresses = Address::findByUserId($user-‐>id); } User Controller Class Address Model Class Address Table