本文介绍了如何在Laravel中为相同模式路由GET和POST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel 4中,有没有人知道将这2行合并为一条的任何方式?

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');

所以不必写两个,都只需要写一个,因为它们都使用"same"方法,而且URL仍然是site.com/login而不是重定向到site.com/auth/login?

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?

我很好奇,因为我记得CI具有类似的含义,其中URL保持不变,并且控制器从不显示:

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';

推荐答案

您可以尝试以下操作:

Route::controller('login','AuthController');

然后在您的AuthController class中实现以下方法:

Then in your AuthController class implement these methods:

public function getIndex();
public function postIndex();

它应该可以工作;)

这篇关于如何在Laravel中为相同模式路由GET和POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:21