laravel ÐÞ¸ÄÇëÇó²ÎÊý
laravelÊÇÒ»¸ö»ùÓÚphpµÄ¿ªÔ´webÓ¦ÓóÌÐò¿ò¼Ü£¬ËüÌṩÁËһЩºÜÊÇÓÐÓõĹ¦Ð§£¬ÀýÈç·ÓÉ£¬ÖÐÐļþ£¬Ä£°åÒýÇæµÈ¡£ÔÚ¿ª·¢Àú³ÌÖУ¬ÎÒÃǾ³£ÐèÒª´¦ÀíÇëÇó²ÎÊý¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlaravelÖÐÐÞ¸ÄÇëÇó²ÎÊý¡£
»ñÈ¡ÇëÇó²ÎÊý
ÔÚLaravelÖУ¬¿ÉÒÔʹÓÃÒÔÏ´úÂëÀ´»ñÈ¡ÇëÇó²ÎÊý£º
$request->input('parameter_name');
µÇ¼ºó¸´ÖÆ
Õ⽫·µ»ØÇëÇó²ÎÊýµÄÖµ¡£ÈôÊÇÇëÇóûÓÐÌṩ¸Ã²ÎÊý£¬Ëü½«·µ»Ønull¡£ÀýÈ磬ÒÔÏ´úÂ뽫»ñÈ¡ÃûΪ¡°id¡±µÄÇëÇó²ÎÊýµÄÖµ£º
$id = $request->input('id');
µÇ¼ºó¸´ÖÆ
ÐÞ¸ÄÇëÇó²ÎÊý
ÓÐʱ¼ä£¬ÎÒÃÇÐèÒªÐÞ¸ÄÇëÇó²ÎÊýµÄÖµ¡£ÀýÈ磬µ±ÎÒÃÇÎüÊÕµ½Ò»¸öÇëÇóʱ£¬ÎÒÃÇÏë¸ü¸ÄһЩ²ÎÊýµÄÖµÀ´¾ÙÐÐÑéÖ¤»ò´¦Àí¡£ÔÚLaravelÖУ¬¿ÉÒÔʹÓÃÒÔÏÂÒªÁìÀ´ÐÞ¸ÄÇëÇó²ÎÊý£º
$request->merge(['parameter_name' => 'new_value']);
µÇ¼ºó¸´ÖÆ
Õ⽫Óá°new_value¡±Ìæ»»ÇëÇó²ÎÊý¡°parameter_name¡±µÄÄ¿½ñÖµ¡£ÀýÈ磬ÒÔÏ´úÂ뽫°ÑÃûΪ¡°id¡±µÄÇëÇó²ÎÊýµÄÖµ¸ü¸ÄΪ¡°new_id¡±£º
$request->merge(['id' => 'new_id']);
µÇ¼ºó¸´ÖÆ
Öض¨Ïò
ÓÐʱ¼ä£¬ÎÒÃÇÐèÒªÔÚ´¦ÀíÇëÇó֮ǰ½«ÇëÇóÖض¨Ïòµ½ÁíÒ»¸öURL¡£ÔÚLaravelÖУ¬¿ÉÒÔʹÓÃÒÔÏÂÒªÁìÖض¨ÏòÇëÇó£º
return redirect()->to('new_url');
µÇ¼ºó¸´ÖÆ
Õ⽫Öض¨ÏòÇëÇ󵽡°new_url¡±¡£µ±ÔÚ¿ØÖÆÆ÷ÖÐʹÓôËÒªÁìʱ£¬¿ÉÒÔÖ´ÐÐÆäËû²Ù×÷£¬ÀýÈ磺
public function index(Request $request) { if ($request->input('id') == null) { $request->merge(['id' => 'default_id']); return redirect()->back(); } // ... }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬ÈôÊÇÇëÇóûÓÐÌṩ¡°id¡±µÄÖµ£¬¿ØÖÆÆ÷½«Í¨¹ý½«Æä¸ü¸ÄΪ¡°default_id¡±À´ÐÞ¸ÄÇëÇó²ÎÊý¡£È»ºó£¬¿ØÖÆÆ÷½«Ê¹ÓÃredirect()->back()½«Óû§Öض¨Ïò»Ø֮ǰµÄÒ³Ãæ¡£
ÖØдÇëÇóÒªÁì
ÓÐʱ¼ä£¬ÎÒÃÇÐèÒª¸ü¸ÄÇëÇóÒªÁì¡£ÀýÈ磬ÎÒÃÇÏ£Íûͨ¹ýPOSTÇëÇó·¢ËÍÊý¾Ý£¬¿ÉÊÇÎÒÃÇÖ»ÓÐGETÇëÇó¡£ÔÚLaravelÖУ¬¿ÉÒÔʹÓÃÒÔÏ´úÂ뽫HTTPÇëÇóÒªÁì¸ü¸ÄΪPOST£º
$request->setMethod('POST');
µÇ¼ºó¸´ÖÆ
Õ⽫ǿÖÆÇëÇóʹÓÃPOSTÒªÁì¡£ÀýÈ磬ÒÔÏ´úÂ뽫ÔÚGETÇëÇóÖиü¸ÄÇëÇóÒªÁ죺
public function index(Request $request) { if ($request->isMethod('GET')) { $request->setMethod('POST'); $request->merge(['id' => 'new_id']); return redirect()->back(); } // ... }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬¿ØÖÆÆ÷½«¼ì²éÇëÇóÊÇ·ñΪGET¡£ÈôÊÇÊÇ£¬Ôò½«Æä¸ü¸ÄΪPOST£¬²¢½«¡°id¡±²ÎÊý¸ü¸ÄΪ¡°new_id¡±¡£È»ºó£¬¿ØÖÆÆ÷½«Ê¹ÓÃredirect()->back()½«Óû§Öض¨Ïò»Ø֮ǰµÄÒ³Ãæ¡£
×ܽá
ÔÚLaravelÖУ¬ÐÞ¸ÄÇëÇó²ÎÊýºÜÈÝÒס£ÒªÁì°üÀ¨»ñÈ¡ÇëÇó²ÎÊý£¬ÐÞ¸ÄÇëÇó²ÎÊý£¬Öض¨ÏòÇëÇóºÍÖØдÇëÇóÒªÁì¡£ÎÞÂÛÄúÊÇÔÚ±àд¿ØÖÆÆ÷ÕÕ¾ÉʹÓÃÖÐÐļþ£¬ÕâЩҪÁ춼¿ÉÒÔ×ÊÖúÄú´¦ÀíÇëÇó¡£
ÒÔÉϾÍÊÇlaravel ÐÞ¸ÄÇëÇó²ÎÊýµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡