Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to route GET and POST for same pattern in Laravel?

Does anyone know of any way in Laravel 4 which combines these 2 lines into one?

Route::get('login', 'AuthController@getLogin'); Route::post('login', 'AuthController@postLogin'); 

So instead of having to write both you only have to write one since their both using the 'same' method but also the URL remains as site.com/login instead of a redirect to site.com/auth/login?

I'm curious since I remember CI has something like that where the URL remains the same and the controller is never shown:

$route['(method1|method2)'] = 'controller/$1'; 
like image 818
enchance Avatar asked Aug 20 '13 02:08

enchance


People also ask

What is route match in Laravel?

Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes. For example, instead of injecting a user's ID, you can inject the entire User model instance that matches the given ID.

What is the difference between route and URL in Laravel?

For a start it is using a named route. This means that the link between the form and its controller are not dictated by the url that the user sees. The next advantage is that you can pass additional parameters into the route helper and it will put those in the correct place in the form action.

How many types of routes are there in Laravel?

Route Parameters Laravel provides two ways of capturing the passed parameter: Required parameter. Optional Parameter.


1 Answers

The docs say...

Route::match(array('GET', 'POST'), '/', function() {     return 'Hello World'; }); 

source: http://laravel.com/docs/routing

like image 120
OrtegaGuillermo Avatar answered Sep 28 '22 11:09

OrtegaGuillermo