Route
Route::get('test', 'HomeController@tryMe');
Controller
<?php
class HomeController extends BaseController {
public function tryMe()
{
echo 'test';
}
}
As far, as i know: this just routes me everytime to the tryMe-Method? What, if i want to call the 'testMe'-Method instead of 'tryMe'?
I do not want to implement a route just for every method i am implementing. Is there nothing like 'just route from the http-uri to the controller/action' ?
As it seems, i MUST set the 'get', 'post', 'put' etc. as a prefix to every method?
Yes - i would like to use this restful-controller. The only thing i do not like is: I have to prefix my methods with 'get', 'post' or something like that. If there would be a way to implement just a 'testme()' and not a 'getTestme()' - THEN i would be happy :-)
Use RESTful controllers.
Route::controller('home', 'HomeController');
Route::controller('city', 'CityController');
Done.
Use HTTP verbs. It'll help you. What are you going to do if you need a method that handles form submission? Are you going to create a method like formSubmit()? Then you have to add restrictions to allow only POST requests to that method. Why not let Laravel handle that for you automatically?
You can do better with something like getTryme() and postTryme() and submit the form to the same URL. When you review your code later, those method names tell you exactly what their roles are.
Having said that, this works:
Route::get('{resource}/{method}', function($resource, $method)
{
$controllerName = ucfirst($resource).'Controller';
$controller = new $controllerName;
return $controller->{$method}();
});
I don't recommend it though.
Thanks. Yes, that's maybe not the best way to setup a routing.
But as it is for migrating an old, complex ZF1-Application it's okay. After we removed all of the old ZF1-Controller-Stuff, the next way could be to implement a new routing. At the moment it's just the simple way to move on to laravel.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community