×ðÁú¿­Ê±

laravelÔõÑùʵÏÖÌøתҳÃæ´ø²ÎÊýµÄ¹¦Ð§

ÔÚlaravel¿ò¼ÜÖÐ £¬ÌøתҳÃæÊǷǾ­³£¼ûµÄ²Ù×÷¡£ÓÐʱ¼äÐèÒªÔÚÌøתʱ´øһЩ²ÎÊý £¬ºÃ±ÈËÑË÷Òªº¦´Ê¡¢·ÖÒ³ÊýµÈµÈ¡£Õâʱ¼ä¾ÍÐèҪʵÏÖÌøתҳÃæ´ø²ÎÊýµÄ¹¦Ð§¡£±¾ÎĽ«ÏÈÈÝÔõÑùʵÏÖÌøתҳÃæ´ø²ÎÊýµÄ¹¦Ð§ £¬ÊµÏÖÎÞÖض¨Ïò´«²Î¡£

1¡¢»ù±¾Ìøת

ÔÚLaravel¿ò¼ÜÖÐ £¬ÌøתÓÐÁ½ÖÖ·½·¨ £¬Ò»ÖÖÊÇʹÓÃredirectº¯Êý £¬ÁíÒ»ÖÖÊÇʹÓÃviewº¯Êý¡£redirectº¯ÊýÓÃÓÚÌøתµ½ÆäËû¿ØÖÆÆ÷µÄÒªÁì £¬viewº¯ÊýÓÃÓÚÌøתµ½ÊÓͼÎļþ¡£

ʹÓÃredirectº¯Êý £¬¿ÉÒÔÕâÑùд£º

return redirect()->action(
    '[¿ØÖÆÆ÷Ãû³Æ]@[ÒªÁìÃû³Æ]'
);

µÇ¼ºó¸´ÖÆ

ʹÓÃviewº¯Êý £¬¿ÉÒÔÕâÑùд£º

return view('[ÊÓͼÎļþ·¾¶]', [²ÎÊýÊý×é]);

µÇ¼ºó¸´ÖÆ

ÕâÁ½ÖÖ·½·¨¶¼Ã»ÓÐת´ï²ÎÊý £¬ÈôÊÇÐèҪת´ï²ÎÊý £¬ÎÒÃÇÐèÒª½ÓÄÉÒÔÏÂÒªÁì¡£

2¡¢´ø²ÎÊýÌøת

2.1¡¢Ê¹ÓÃÖÐÐļþ

LaravelÌṩÁ˺ÜÊÇÀû±ãµÄÖÐÐļþ¹¦Ð§ £¬ÎÒÃÇ¿ÉÒÔʹÓÃÖÐÐļþ½«²ÎÊýת´ïµ½ÏÂÒ»¸öÇëÇóÖС£

ÎÒÃÇ¿ÉÒÔн¨Ò»ÆäÖÐÐļþ £¬ÔÚÖÐÐļþÖн«²ÎÊýÉúÑÄÆðÀ´ £¬È»ºóÔÚÏÂÒ»¸öÇëÇóÖÐÈ¡³öÕâЩ²ÎÊý¡£ÖÐÐļþ´úÂëÈçÏ£º

<?php namespace App\Http\Middleware;

use Closure;

class ParamsMiddleware
{
    public function handle($request, Closure $next)
    {
        $params = [
            'param1' => 'value1',
            'param2' =&gt; 'value2',
            'param3' =&gt; 'value3',
        ];
        
        $request-&gt;session()-&gt;put('params', $params);
        
        return $next($request);
    }
}

µÇ¼ºó¸´ÖÆ

½«²ÎÊýÉúÑÄÔÚsessionÖÐ £¬È»ºóÔÚÏÂÒ»¸öÇëÇóÖÐÈ¡³öÀ´¡£

$params = $request-&gt;session()-&gt;get('params');

µÇ¼ºó¸´ÖÆ

ÎÒÃÇ¿ÉÒÔÔÚweb.phpÎļþÖÐ×¢²áÖÐÐļþ £¬²¢½«ÖÐÐļþÌí¼Óµ½Â·ÓÉÖС£

Route::middleware('params')-&gt;get('/', '[¿ØÖÆÆ÷Ãû³Æ]@[ÒªÁìÃû³Æ]');

µÇ¼ºó¸´ÖÆ

ÕâÖÖ·½·¨µÄÈõµãÊÇÐèҪʹÓÃsession £¬ÈôÊÇûÓпªÆôsession £¬ÔòÎÞ·¨Ê¹Óá£

2.2¡¢Ê¹ÓÃURL²ÎÊý

ÎÒÃÇ»¹¿ÉÒÔʹÓÃURL²ÎÊý½«²ÎÊýת´ïµ½ÏÂÒ»¸öÒ³ÃæÖС£

ÔÚÌøתʱ £¬ÎÒÃÇ¿ÉÒÔʹÓÃrouteº¯ÊýÖ¸¶¨Â·ÓÉ £¬È»ºóÔÚ·ÓÉÖÐÉèÖòÎÊý¡£

Ìøת´úÂ룺

return redirect()-&gt;route('[·ÓÉÃû³Æ]', ['param1' =&gt; 'value1', 'param2' =&gt; 'value2']);

µÇ¼ºó¸´ÖÆ

·ÓÉ´úÂ룺

Route::get('/', '[¿ØÖÆÆ÷Ãû³Æ]@[ÒªÁìÃû³Æ]')-&gt;name('[·ÓÉÃû³Æ]');

µÇ¼ºó¸´ÖÆ

ÔÚ¿ØÖÆÆ÷ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃrequest¹¤¾ß»ñÈ¡URL²ÎÊý¡£

$request-&gt;input('param1');

µÇ¼ºó¸´ÖÆ

ÕâÖÖ·½·¨µÄÈõµãÊÇURL²ÎÊý»áÏÔʾÔÚURLµØµãÀ¸ÖÐ £¬¿ÉÄÜ»á¶ÔÓû§Ôì³ÉÒ»¶¨µÄÀ§ÈÅ¡£

2.3¡¢Ê¹ÓÃÖض¨Ïò²ÎÊý

LaravelÌṩÁËÁíÒ»ÖÖÒªÁì £¬¿ÉÒÔʵÏÖÎÞÖض¨Ïò´«²Î¡£ÎÒÃÇÏÈ¿´´úÂë £¬È»ºóÔÚÚ¹ÊÍ¡£

return redirect()-&gt;to('/')-&gt;with('param1', 'value1')-&gt;with('param2', 'value2');

µÇ¼ºó¸´ÖÆ

ÔÚÖض¨Ïòʱ £¬ÎÒÃÇ¿ÉÒÔʹÓÃwithº¯Êý½«²ÎÊýÉúÑÄÔÚsessionÖС£ÕâÑù £¬²ÎÊý¾Í¿ÉÒÔÔÚÏÂÒ»¸öÇëÇóÖÐʹÓÃÁË¡£

ÔÚ¿ØÖÆÆ÷ÖÐ £¬ÎÒÃÇ¿ÉÒÔÕâÑù»ñÈ¡²ÎÊý¡£

$request-&gt;session()-&gt;get('param1');
$request-&gt;session()-&gt;get('param2');

µÇ¼ºó¸´ÖÆ

ÕâÖÖ·½·¨ÊµÏÖÁËÎÞÖض¨Ïò´«²Î £¬Í¬Ê±Ò²×èÖ¹ÁËURL²ÎÊý¶ÔÓû§µÄ×ÌÈÅ¡£

×ܽá

ÔÚLaravelÖÐ £¬ÊµÏÖÌøתҳÃæ´ø²ÎÊýµÄ¹¦Ð§ÓжàÖÖÒªÁì¡£¿ÉÒÔʹÓÃÖÐÐļþ¡¢URL²ÎÊý»òÕßÖض¨Ïò²ÎÊý¡£²î±ðµÄÒªÁìÓвî±ðµÄÓÅÈõµã £¬ÎÒÃÇÐèҪƾ֤ÏÖʵÐèÇóÑ¡Ôñ×îºÏÊʵÄÒªÁì¡£

ÒÔÉϾÍÊÇlaravelÔõÑùʵÏÖÌøתҳÃæ´ø²ÎÊýµÄ¹¦Ð§µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿