N
N
naneri2014-08-13 09:43:41
Laravel
naneri, 2014-08-13 09:43:41

How does dynamic routing work in laravel?

I registered the following route in the router in Laravel: In theory, it should send all requests like "yoursite/post/{method}/{arg1}/..." to the controller "PostController", but for some reason it does not see the routes at all and how I understood that it cannot produce dynamic routing at all (that is, you need to specify a route for each URL). (Gives an error "Route [post/add] not defined" although I have a "getAdd" method and I even tried to rename it simply to "add" Did I understand everything correctly, or is it still possible not to prescribe?
Route::controller('post', 'PostController');

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2014-08-13
@naneri

Laravel uses Symfony/Routing. Purely theoretically, with the help of expressions, you can implement dynamic routing, but in general this approach is considered un-feng shui.
But generally yes. One controller action - one or more routes.

V
Vyacheslav Plisko, 2014-08-13
@AmdY

(Gives a "Route [post/add] not defined" error even though I have a "getAdd" method

Actions should consist of a request method and a name from the url
if the post is a request, then the name will be public function postAdd(....), not getAdd

C
claymor, 2014-11-14
@claymor

Weird.
Router: Route::controller('test', 'TestController');
request URL: site.../test/add/12
Normally caught by a method in the TestController controller
public function getAdd($param) {
return $param; //result 12
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question