Laravel

Laravel Routing

Basic routes, parameters, named routes, route groups, middleware, resource routes, route model binding

20 면접 질문·
Junior
1

How to define a basic GET route in Laravel?

답변

The Route::get() method defines a route that responds to HTTP GET requests. The first parameter is the URI, the second is either a closure or an array [Controller::class, 'method']. This approach is defined in routes/web.php or routes/api.php depending on the route type.

2

Which method to use to create a route that responds to multiple HTTP verbs?

답변

Route::match() accepts an array of HTTP verbs as the first parameter, then the URI and action. This allows responding to GET and POST on the same route for example. Route::any() also exists to respond to all HTTP verbs, but match() offers more precise control.

3

How to capture a parameter in a route URL?

답변

Route parameters are defined using curly braces {param} in the URI. They are automatically injected into the closure or controller method. Parameters can be made optional with {param?} and accept constraints with ->where().

4

How to add a regex constraint on a route parameter?

5

How to name a route for easy reuse?

+17 면접 질문

다음 면접을 위해 Laravel을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기