Answer the question
In order to leave comments, you need to log in
Laravel: how to make routes like in Kohana?
Kohan has this default route:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
(<controller>(/<action>(/<id>)))
are optional, they are executed if they exist and they are in the url. Answer the question
In order to leave comments, you need to log in
no way. As far as I remember, symfony/routing doesn't allow this, and that's a good thing.
Write the last route something like
Route::any('{controller}/{action?}', function($controller, $action = 'index') {
return call_user_func_array([App::make(ucwords($controller). 'Controller'), $action], array_slice(func_get_args(), 2));
});
I found a very convenient way for me.
In the routes we write the name of the controller.
Method names start with get and post
class QuestionController extends BaseController {
public function getIndex() { // example.com/question
//
}
// для POST запроса на адрес example.com/question/new
public function postNew() {
//
}
public function getItem($id) { // example.com/question/item/1
//
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question