Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 1.52 KB

File metadata and controls

61 lines (43 loc) · 1.52 KB

Маршрутизация

Маршруты определяются в файле routes.php вашего приложения.

Простые маршруты

use Pet\Router\Router;

Router::get('/', function() {
    return 'Hello, World!';
});

Router::post('/user', [UserController::class, 'store']);

Поддерживаемые HTTP-методы

Гибкие URL (параметры в пути)

Router::get('/user/{id}', [UserController::class, 'show']);
// /user/42 → $id = 42

Параметры извлекаются через функцию supple():

function show() {
    $id = supple('id'); // 42
}

Wildcard маршруты

Router::get('/admin/*', [AdminController::class, 'handle']);

Именованные маршруты и группы

Router::get('/dashboard', [DashboardController::class, 'index'])
    ->name('dashboard')
    ->group('admin');

Middleware

use Pet\Router\Middleware;

Middleware::middleware(AuthMiddleware::class)
    ->get('/profile', [ProfileController::class, 'index'])
    ->post('/profile', [ProfileController::class, 'update']);