ÁÄÁÄlaravelÖÐÐļþʵÏÖÔÀí
ÔÚlaravel¿ò¼ÜÖУ¬ÖÐÐļþ£¨middleware£©ÊÇÒ»¸öÖ÷ÒªµÄ¿´·¨£¬¿ÉÒÔ×ÊÖú¿ª·¢ÕßÔÚÇëÇó´¦Öóͷ£Àú³ÌÖÐÌí¼ÓÌØÁíÍâÂß¼´¦Öóͷ££¬ÒÔʵÏÖ¸üÎÞа¡¢¸ü¸ßЧµÄÓ¦ÓóÌÐò¡£
±¾ÎĽ«ÏÈÈÝLaravelÖÐÐļþµÄʵÏÖÔÀí£¬°üÀ¨ÖÐÐļþµÄ×¢²á¡¢Ö´ÐÐÁ÷³ÌÒÔ¼°³£¼ûÓ¦Óó¡¾°¡£
Ò»¡¢ÖÐÐļþµÄ×¢²á
ÔÚLaravel¿ò¼ÜÖУ¬ÖÐÐļþµÄ×¢²áͨ³£ÊÇÔÚ·ÓÉÉèÖÃÎļþÖоÙÐеġ£¹ØÓÚÿ¸öÐèҪʹÓÃÖÐÐļþµÄ·ÓÉ£¬¿ÉÒÔͨ¹ýrouteÒªÁìÀ´½ç˵ÏìÓ¦µÄÖÐÐļþÁÐ±í£¬ÀýÈ磺
Route::get('/user', 'UserController@index')->middleware(['auth', 'admin']);
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬½ç˵ÁË»á¼û¡°/user¡±Â·ÓÉʱÐèҪʹÓá°auth¡±ºÍ¡°admin¡±Á½ÆäÖÐÐļþ¡£
ͬʱ£¬Ò²¿ÉÒÔͨ¹ýÈ«¾ÖÖÐÐļþ×¢²áÀ´ÊµÏÖÓ¦ÓóÌÐòµÄÈ«¾Ö¹ýÂË£¬ÀýÈ磺
protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, // ... ];
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬½ç˵ÁËLaravelĬÈÏÌṩµÄһЩȫ¾ÖÖÐÐļþ£¬ÒÔÓÃÓÚÔÚÇëÇó´¦Öóͷ£Àú³ÌÖоÙÐÐУÑé¡¢¹ýÂ˵ȹ¦Ð§¡£
¶þ¡¢ÖÐÐļþµÄÖ´ÐÐÁ÷³Ì
ÔÚLaravel¿ò¼ÜÖУ¬Ã¿´ÎÇëÇóµÖ´ïÓ¦ÓóÌÐòʱ£¬»áÒÀ´ÎÖ´ÐÐһϵÁеÄÖÐÐļþ´¦Öóͷ£Àú³Ì£¬ÒÔÈ·±£ÇëÇóµÄ¿É¿¿ÐÔºÍÇå¾²ÐÔ¡£¶øÖÐÐļþµÄÖ´ÐÐÁ÷³Ìͨ³£·ÖΪÒÔϼ¸¸ö½×¶Î£º
ÇëÇóµÖ´ïÖÐÐļþ´¦Öóͷ£½×¶Î
µ±ÇëÇóµÖ´ïÓ¦ÓóÌÐòʱ£¬Ê×ÏÈ»á½øÈëµ½ÖÐÐļþ´¦Öóͷ£½×¶Î¡£´Ëʱ£¬Laravel»áƾ֤·Óɽç˵ÖеÄÖÐÐļþÁÐ±í£¬ÔÚÈ«¾ÖÖÐÐļþÁбíÖвéÕÒÏà¹ØµÄÖÐÐļþ£¬²¢ÒÔÏȽøÏȳöµÄ˳Ðò°´Ë³ÐòÖ´ÐС£
ÖÐÐļþ´¦Öóͷ£Àú³Ì
ÔÚÖÐÐļþ´¦Öóͷ£Àú³ÌÖУ¬Laravel»áƾ֤ÖÐÐļþµÄ×¢²á˳ÐòÒ»¸ö¸öÖ´ÐÐÖÐÐļþ´¦Öóͷ£º¯Êý¡£¹ØÓÚÿÆäÖÐÐļþ£¬ÈôÊÇÆä´¦Öóͷ£·½·¨·µ»Øfalse£¬ÔòÖ´ÐÐÖÕÖ¹£¬²¢·µ»Øµ½ÇëÇóÏìÓ¦Àú³ÌÖС£²»È»£¬¼ÌÐøÖ´ÐÐÏÂÒ»ÆäÖÐÐļþ¡£
ÇëÇóÏìÓ¦´¦Öóͷ£½×¶Î
µ±ËùÓÐÖÐÐļþ´¦Öóͷ£¿¢Êºó£¬ÇëÇóµÄÏìÓ¦Àú³Ì²Å»á×îÏÈÖ´ÐС£´Ëʱ£¬Laravel»á·µ»ØÖ´ÐÐÍêËùÓÐÖÐÐļþºóµÄ²Ù×÷Ч¹û¡£
Èý¡¢ÖÐÐļþµÄ³£¼ûÓ¦Óó¡¾°
ÖÐÐļþÔÚLaravel¿ò¼ÜÖеÄÓ¦ÓúÜÊÇÆձ飬¿ÉÒÔ¶ÔÇëÇó¾ÙÐÐÉí·ÝÈÏÖ¤¡¢²ÎÊýУÑé¡¢¿çÓò´¦Öóͷ£¡¢»º´æ¿ØÖƵȶàÖÖ²Ù×÷¡£
Éí·ÝÈÏÖ¤
Éí·ÝÈÏÖ¤ÊÇÓ¦ÓóÌÐòÖкÜÊÇÖ÷ÒªµÄÒ»»·£¬¿ÉÒÔʹÓÃÖÐÐļþÀ´´¦Öóͷ£Óû§ÈÏÖ¤ÐÅÏ¢¡£ÀýÈ磬ÔÚ·Óɽç˵ÖУ¬¿ÉÒÔÌí¼ÓÒ»¸ö¡°auth¡±ÖÐÐļþ£¬ÒÔ±ãÔÚ»á¼ûÐèÒªÉÏ°¶È¨ÏÞµÄÒ³Ãæʱ£¬×Ô¶¯Ìøתµ½ÉÏ°¶Ò³Ãæ¡£
²ÎÊýУÑé
ÔÚÓ¦ÓóÌÐòÖУ¬¾³£ÐèÒª¶ÔÊäÈë²ÎÊý¾ÙÐÐУÑéÒÔÈ·±£Êý¾ÝµÄºÏÀíÐÔºÍÇå¾²ÐÔ¡£¿ÉÒÔʹÓÃÖÐÐļþÀ´ÊµÏÖ²ÎÊýУÑ飬ÀýÈ磬ÔÚ·Óɽç˵ÖУ¬¿ÉÒÔÌí¼ÓÒ»¸ö¡°checkparam¡±ÖÐÐļþ£¬ÒÔ±ãÔÚ»á¼ûÐèÒªÌض¨²ÎÊýµÄÒ³Ãæʱ£¬×Ô¶¯Ð£Ñé²ÎÊýÊÇ·ñÇкÏÒªÇó¡£
¿çÓò´¦Öóͷ£
ÔÚÓ¦ÓóÌÐòÖУ¬¾³£ÐèҪʵÏÖ¿çÓòÇëÇó´¦Öóͷ£ÒÔ˳Ӧ²î±ðµÄÇ°¶ËÊÖÒÕÕ»¡£¿ÉÒÔʹÓÃÖÐÐļþÀ´ÊµÏÖ¿çÓò´¦Öóͷ££¬ÀýÈ磬ÔÚÈ«¾ÖÖÐÐļþÖÐÌí¼ÓÒ»¸ö¡°crossdomain¡±ÖÐÐļþ£¬ÒÔ±ã×Ô¶¯´¦Öóͷ£ËùÓпçÓòÇëÇó¡£
»º´æ¿ØÖÆ
ÔÚÓ¦ÓóÌÐòÖУ¬¾³£ÐèÒª¶ÔÏìӦЧ¹û¾ÙÐлº´æÒÔÌá¸ßÓ¦ÓóÌÐòµÄÏìÓ¦ËÙÂÊ¡£¿ÉÒÔʹÓÃÖÐÐļþÀ´ÊµÏÖ»º´æ¿ØÖÆ£¬ÀýÈ磬ÔÚ·Óɽç˵ÖУ¬¿ÉÒÔÌí¼ÓÒ»¸ö¡°cache¡±ÖÐÐļþ£¬ÒÔ±ãÔÚÇëÇó´¦Öóͷ£Àú³ÌÖÐ×Ô¶¯»º´æÊý¾Ý£¬²¢¶ÔÊý¾Ý¾ÙÐиüС¢»Ø¹öµÈ²Ù×÷¡£
×ÛÉÏËùÊö£¬ÖÐÐļþÊÇLaravel¿ò¼ÜÖкÜÊÇÖ÷ÒªµÄÒ»¸ö¿´·¨£¬¿ÉÓÃÓÚʵÏÖÉí·ÝÈÏÖ¤¡¢²ÎÊýУÑé¡¢¿çÓò´¦Öóͷ£¡¢»º´æ¿ØÖƵȶàÖÖ¹¦Ð§£¬ÎªÓ¦ÓóÌÐòµÄÎȹÌÐԺͿɿ¿ÐÔÌṩÁËÒªº¦µÄÖ§³Ö¡£
ÒÔÉϾÍÊÇÁÄÁÄlaravelÖÐÐļþʵÏÖÔÀíµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡