728x90
반응형
1. 관리자 삭제를 위한 저장 프로시저(deleteAdmin)을 만들어봅시다.
$ mysql -u xyz -pxyz123 xyz
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 271
Server version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
DELIMITER $$
CREATE PROCEDURE deleteAdmin (i_sno INT)
BEGIN
DELETE FROM admins WHERE sno = i_sno;
END $$
DELIMITER ;
mysql> CALL listAdmins();
+-----+---------+-----------+---------+
| sno | userid | password | nick |
+-----+---------+-----------+---------+
| 1 | testid1 | passwd101 | nick101 |
| 2 | testid2 | passwd2 | nick2 |
| 3 | testid3 | passwd3 | nick3 |
| 4 | testid4 | passwd4 | nick4 |
| 5 | testid5 | passwd5 | nick502 |
| 9 | testid6 | passwd106 | nick601 |
+-----+---------+-----------+---------+
6 ROWS IN SET (0.00 sec)
Query OK, 0 ROWS affected (0.00 sec)
mysql> CALL deleteAdmin(9);
Query OK, 1 ROW affected (0.01 sec)
mysql> CALL listAdmins();
+-----+---------+-----------+---------+
| sno | userid | password | nick |
+-----+---------+-----------+---------+
| 1 | testid1 | passwd101 | nick101 |
| 2 | testid2 | passwd2 | nick2 |
| 3 | testid3 | passwd3 | nick3 |
| 4 | testid4 | passwd4 | nick4 |
| 5 | testid5 | passwd5 | nick502 |
+-----+---------+-----------+---------+
5 ROWS IN SET (0.00 sec)
Query OK, 0 ROWS affected (0.00 sec)
mysql> exit
2. xyz/app/Http/Controllers/Mgmt/Admin.php 에 다음을 추가한다.
...
// 관리자 삭제
// /mgmt/admin/delete/{id}
public function delete ($id) {
DB::delete('CALL deleteAdmin(?)', [$id]);
return redirect('/mgmt/admin');
}
...
3. xyz/routes/web.php 에 다음을 추가하고, 관리자 삭제를 해봅니다.
Route::get('admin/delete/{id}', [Admin::class, 'delete']);
4. 여기까지 하면, 기본적인 CRUD 기능을 모두 작성할 수 있게 됩니다. *^^*
728x90
반응형
'Framework (Backend) > Laravel' 카테고리의 다른 글
(Lavavel) 로그인/로그아웃 처리하기 : Laravel 8.x (0) | 2021.09.19 |
---|---|
(Lavavel) 비밀번호 단방향암호화(SHA256) 하기 : Laravel 8.x, MySQL (0) | 2021.08.29 |
(Lavavel) 관리자 수정하기 : Laravel 8.x (0) | 2021.08.29 |
(Lavavel) 관리자 비밀번호 변경하기 : Laravel 8.x (0) | 2021.08.28 |
(Lavavel) 관리자 추가하기 : Laravel 8.x (0) | 2021.08.24 |
댓글