laravel Ä£°æÄÚÀïÔõô»ñÈ¡Ä¿½ñÒªÁì
ÔÚ laravel ÖУ¬»ñÈ¡Ä¿½ñÒªÁì¿ÉÒÔʹÓà illuminatehttprequest ÀàµÄ method() ÒªÁì¡£¸ÃÒªÁ콫·µ»ØÄ¿½ñÇëÇóµÄ http ÒªÁì¡£
ÔÚ Laravel µÄ Blade Ä£°åÖУ¬¿ÉÒÔʹÓà {{ request()->method() }} »ñÈ¡Ä¿½ñÇëÇóµÄÒªÁì¡£ÀýÈ磺
@if (request()->method() == 'POST') ÇëÇó·½·¨Îª POST @elseif (request()->method() == 'GET') ÇëÇó·½·¨Îª GET @else ÇëÇó·½·¨ÎªÆäËü @endif
µÇ¼ºó¸´ÖÆ
ÔÚ¿ØÖÆÆ÷ÖУ¬¿ÉÒÔʹÓà $request->method() »ò $request->getMethod() »ñÈ¡Ä¿½ñÇëÇóµÄÒªÁì¡£ÀýÈ磺
public function index(Request $request) { if ($request->method() == 'POST') { // ´¦Àí POST ÇëÇó } if ($request->getMethod() == 'GET') { // ´¦Àí GET ÇëÇó } }
µÇ¼ºó¸´ÖÆ
ÁíÍ⣬ÔÚ¿ØÖÆÆ÷ÖУ¬Ò²¿ÉÒÔʹÓà PHP ÄÚÖÃµÄ $_SERVER[‘REQUEST_METHOD’] ±äÁ¿»ñÈ¡Ä¿½ñÇëÇóµÄÒªÁì¡£ÀýÈ磺
public function index() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { // ´¦Àí POST ÇëÇó } if ($_SERVER['REQUEST_METHOD'] == 'GET') { // ´¦Àí GET ÇëÇó } }
µÇ¼ºó¸´ÖÆ
ÐèҪעÖصÄÊÇ£¬Ê¹Óà $_SERVER[‘REQUEST_METHOD’] ±äÁ¿µÄ·½·¨²»ÈçʹÓà Laravel ÌṩµÄ Request ÀàµÄ·½·¨ÓÅÑźÍÀû±ã¡£
ÒÔÉϾÍÊÇlaravel Ä£°æÄÚÀïÔõô»ñÈ¡Ä¿½ñÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡
ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£