The router keeps route registration and dispatch lightweight.
Available facade:
Route
use Myxa\Support\Facades\Route;
use Myxa\Support\Facades\Response;
Route::get('/health', static function () {
return Response::json(['ok' => true]);
});
Route::post('/users', [UserController::class, 'store']);The router supports the common HTTP verbs directly:
Route::get('/posts', [PostController::class, 'index']);
Route::post('/posts', [PostController::class, 'store']);
Route::put('/posts/{id}', [PostController::class, 'replace']);
Route::patch('/posts/{id}', [PostController::class, 'update']);
Route::delete('/posts/{id}', [PostController::class, 'destroy']);
Route::options('/posts', [PostController::class, 'options']);
Route::head('/posts', [PostController::class, 'head']);Typical use:
put()for full replacement updatespatch()for partial updatesdelete()for record removaloptions()for capability/preflight responseshead()for header-only responses
Use match() when one route should accept several methods:
Route::match(['GET', 'POST'], '/search', [SearchController::class, 'handle']);Use any() when a route should accept the common HTTP methods:
Route::any('/webhook', [WebhookController::class, 'handle']);Routes support named path parameters:
Route::get('/users/{id}', [UserController::class, 'show']);
Route::get('/posts/{postId}/comments/{commentId}', [CommentController::class, 'show']);Handler arguments are resolved from the route parameters:
Route::get('/users/{id}', static function (string $id) {
return "User {$id}";
});Middleware can be attached directly to a route:
use Myxa\Middleware\AuthMiddleware;
Route::delete('/posts/{id}', [PostController::class, 'destroy'])
->middleware(AuthMiddleware::using('api'));
Route::get('/dashboard', [DashboardController::class, 'show'])
->middleware(AuthMiddleware::using('web'));Use groups to share a common path prefix:
Route::group('/api', static function (): void {
Route::get('/users', [UserController::class, 'index']);
Route::get('/users/{id}', [UserController::class, 'show']);
Route::post('/users', [UserController::class, 'store']);
});You can also attach middleware to the whole group:
use Myxa\Middleware\AuthMiddleware;
Route::group('/api', static function (): void {
Route::get('/me', [ProfileController::class, 'show']);
Route::patch('/me', [ProfileController::class, 'update']);
}, [AuthMiddleware::using('api')]);Use middleware() when you want shared middleware without adding a path prefix:
use Myxa\Middleware\AuthMiddleware;
Route::middleware([AuthMiddleware::using('web')], static function (): void {
Route::get('/dashboard', [DashboardController::class, 'show']);
Route::get('/settings', [SettingsController::class, 'show']);
});use Myxa\Support\Facades\Route;
$result = Route::dispatch();You can also inspect routes directly:
$exists = Route::has('GET', '/health');
$route = Route::find('GET', '/health');
$allRoutes = Route::routes();- routes support path parameters like
/users/{id} - handlers can be closures, object methods, or
[Controller::class, 'method'] - middleware can be attached per route or by group
- auth middleware can be attached with
AuthMiddleware::using('web')orAuthMiddleware::using('api') match()andany()are useful for shared endpoints like search pages and webhooksRouteServiceProviderregisters the shared router and initializes theRoutefacade