-
Notifications
You must be signed in to change notification settings - Fork 0
Routing
Tirapong Chaiyakun edited this page Sep 19, 2026
·
1 revision
กำหนดเส้นทางใน Routes/web.php
use Core\Route;
use Core\Response;
Route::get('/users', 'UserController@index');
Route::post('/users', 'UserController@store');
Route::put('/users/{id}', 'UserController@update');
Route::patch('/users/{id}', 'UserController@patch');
Route::delete('/users/{id}', 'UserController@destroy');
Route::options('/users', fn () => Response::json([]));
Route::any('/ping', fn () => Response::json(['pong' => true]));ค่า controller เป็นสตริง ชื่อคลาส@เมธอด ระบบเติม namespace App\Controllers\ ให้อัตโนมัติ
ใช้ Closure ได้เช่นกัน
{id} ถูกส่งเป็นอาร์กิวเมนต์ถัดจาก Request
public function update(Request $request, string $id): never
{
$this->json(['id' => $id]);
}use Core\Middleware\JwtAuth;
Route::group('/api', ['middleware' => JwtAuth::class], function () {
Route::get('/me', 'UserController@me');
});หรือใส่ทีละเส้นทาง
Route::get('/me', 'UserController@me', ['middleware' => JwtAuth::class]);Middleware ต้องมีเมธอด handle(Request $request, callable $next): void
JWT ที่มากับ Authorization: Bearer ... ตรวจใน Core\Middleware\JwtAuth ถ้าไม่ผ่านจะตอบ 401
| Path | ความหมาย |
|---|---|
GET / |
JSON ต้อนรับ |
GET /health |
ต่อฐานข้อมูลได้หรือไม่ |
GET /testview |
ตัวอย่าง View |