Tạo StudentController@index & Hiển thị mảng tĩnh trên Blade View
Khởi tạo Controller bằng lệnh php artisan make:controller StudentController, khai báo mảng tĩnh gồm 5 sinh viên và truyền sang view resources/views/students/index.blade.php kế thừa từ layout layouts/app.blade.php.
Danh sách Sinh viên (Nguồn: Mảng tĩnh trong Controller)
Route:GET /students/static → StudentController@staticIndex
| #ID | Họ và tên | Tuổi | Giới tính | |
|---|---|---|---|---|
| #= (int) $st['id'] ?> | = htmlspecialchars($st['name']) ?> | = htmlspecialchars($st['email']) ?> |
= (int) $st['age'] ?> tuổi | Nam (Male) Nữ (Female) |
1. app/Http/Controllers/StudentController.php
= htmlspecialchars($controllerCode) ?>
2. resources/views/layouts/app.blade.php
= htmlspecialchars($layoutCode) ?>
3. resources/views/students/index.blade.php
= htmlspecialchars($viewCode) ?>