ÁÄÁÄ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ÖÐÐļþʵÏÖÔÀíµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡