×ðÁú¿­Ê±¹ÙÍøµÇ¼

Laravel¿ª·¢£ºÔõÑùʹÓÃLaravel GuardÖÎÀíÓû§Éí·ÝÑéÖ¤£¿

laravel¿ª·¢£ºÔõÑùʹÓÃlaravel guardÖÎÀíÓû§Éí·ÝÑéÖ¤£¿

ÔÚWebÓ¦ÓóÌÐòÖÐ £¬Çå¾²ÐÔºÍÓû§Éí·ÝÑéÖ¤ÊÇÖÁ¹ØÖ÷ÒªµÄ¡£Ëæ×ÅÓªÒµµÄÔöÌí £¬Óû§µÄÊýÄ¿Ò²»áÔöÌí £¬ÈôÊÇûÓÐʵÑéÓÅÒìµÄÓû§Éí·ÝÑéÖ¤¼Æ»® £¬Ó¦ÓóÌÐò¿ÉÄÜ»áÈÝÒ×Êܵ½ÖÖÖÖ¹¥»÷ £¬°üÀ¨¶ñÒâ¹¥»÷¡¢Êý¾Ýй¶ºÍÆäËûÇå¾²ÎÊÌâ¡£

ÐÒÔ˵ÄÊÇ £¬Laravel¿ò¼ÜÌṩÁËÒ»ÖÖ¼òÆÓ¶øÓÐÓõÄÒªÁìÀ´´¦ÀíÓû§Éí·ÝÑéÖ¤¡£ÕâÖÖÒªÁì±»³ÆΪGuard £¬ËüÔÊÐíÎÒÃǽ¨Éè¶à¸öÓû§Éí·ÝÑé֤ϵͳ²¢ÎªÃ¿¸öϵͳÌṩ²î±ðµÄ¿ØÖƺÍÖÎÀí¡£

ÔÚ±¾ÎÄÖÐ £¬ÎÒ½«Ïò¸÷ÈËÏÈÈÝÔÚLaravelÖÐÔõÑùʹÓÃGuardÀ´ÖÎÀíÓû§Éí·ÝÑéÖ¤¡£ÎÒ½«º­¸ÇÒÔÏÂÖ÷Ì⣺

1¡¢Ê²Ã´ÊÇGuard£¿

2¡¢ÔõÑùÔÚLaravelÖн¨ÉèGuard£¿

3¡¢ÔõÑùʹÓÃGuard¾ÙÐÐÓû§Éí·ÝÑéÖ¤£¿

ʲôÊÇGuard£¿

GuardÊÇLaravelÖеÄÒ»¸öÄÚÖù¦Ð§¡£ËüÔÊÐíÎÒÃÇΪӦÓóÌÐò½¨Éè¶à¸öÉí·ÝÑé֤ϵͳ £¬²¢ÎªÃ¿¸öϵͳÌṩ²î±ðµÄ¿ØÖƺÍÖÎÀí¡£Guard»ù±¾ÉÏÈÏÕæÊÚȨÓû§¶ÔÓ¦ÓóÌÐòµÄ»á¼û £¬²¢È·±£Ö»ÓÐÕýµ±Óû§²Å»ªÖ´ÐÐÌض¨µÄ²Ù×÷¡£Guard»¹ÔÊÐíÎÒÃÇͨ¹ý¶à¸öÇý¶¯À´ÖÎÀíÓû§µÇ¼ϵͳ £¬ÀýÈçsessionºÍtoken¡£

ÔÚLaravelÖÐ £¬Guard»ù±¾ÉÏÓÉÒÔÏÂÈý¸ö×é¼þ×é³É£º

1¡¢Provider£ºÌṩÕß £¬ÓÃÓÚ´ÓÊý¾Ý´æ´¢ÇøÖжÁÈ¡ÑéÖ¤ÐÅÏ¢¡£

2¡¢Usermodel£ºÓû§Ä£×Ó £¬ÓÃÓÚÖ¸¶¨Óû§¹¤¾ßÔÚÓ¦ÓóÌÐòÖеÄλÖá£

3¡¢Guard£ºÖÎÀíÔÚÓ¦ÓóÌÐòÖоÙÐÐÉí·ÝÑéÖ¤µÄʵÀý¡£

ͨ¹ýÕâÈý¸ö×é¼þ £¬Guard¿ÉÒÔÓÃÐí¶à·½·¨¾ÙÐÐÀ©Õ¹ £¬´Ó¶ø¸üºÃµØÖª×ãÓû§Éí·ÝÑéÖ¤µÄÒªÇó¡£

ÔõÑùÔÚLaravelÖн¨ÉèGuard£¿

ÏÖÔÚ £¬ÎÒÃÇÖªµÀʲôÊÇGuard £¬²¢ÇÒÓµÓÐGuardÒªÔõÑùÖÎÀíÓû§Éí·ÝÑéÖ¤µÄ¿´·¨¡£ÏÂÃæÎÒÃǽ«ÉîÈë̽ÌÖÔõÑùÔÚLaravelÖн¨ÉèGuard¡£

ÔÚLaravelÖн¨ÉèGuardºÜÊǼòÆÓ¡£Laravel¿ò¼ÜÌṩÁËÒ»¸öartisanÏÂÁîÀ´Ð­ÖúÎÒÃÇÍê³É´ËʹÃü¡£¼ÙÉèÎÒÃÇÏëΪӦÓóÌÐò½¨ÉèÒ»¸öÃûΪ¡°web¡±µÄGuard £¬ÎÒÃÇ¿ÉÒÔÔËÐÐÒÔÏÂÏÂÁ

php artisan make:auth

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁî»á×Ô¶¯ÔÚÎÒÃǵÄÓ¦ÓóÌÐòÖн¨ÉèÒ»¸öÃûΪ¡°web¡±µÄGuard¡£±ðµÄ £¬Ëü»¹»á×Ô¶¯½¨ÉèÎÒÃÇÐèÒª´¦ÀíÉí·ÝÑéÖ¤ËùÐèµÄÊÓͼ¡¢¿ØÖÆÆ÷ºÍ·ÓÉ¡£

ÏÖÔÚ £¬ÎÒÃÇ¿ÉÒÔ»ùÓÚweb GuardÀ´ÖÎÀíÓû§Éí·ÝÑéÖ¤ £¬²¢¿ÉÒÔ½«ÆäÓÃÓÚÓ¦ÓóÌÐòµÄÈκβ¿·Ö¡£

ÔõÑùʹÓÃGuard¾ÙÐÐÓû§Éí·ÝÑéÖ¤£¿

GuardÔÚLaravelÖеÄÖ÷ҪĿµÄÊÇΪÎÒÃÇÌṩһÖÖ¼òÆÓ¶øÓÐÓõÄÒªÁìÀ´ÖÎÀíÓû§Éí·ÝÑéÖ¤¡£ËüÌṩÁËÒ»¸öÎÞаµÄ¼Ü¹¹ £¬¿ÉÒÔÈÃÎÒÃÇÇáËɵØÑéÖ¤Óû§µÄƾ֤²¢ÊÚȨËûÃÇ»á¼ûÓ¦ÓóÌÐòÖеÄijЩÌض¨ÇøÓò¡£

ÔÚLaravelÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃGuardÀàÀ´ÑéÖ¤Óû§µÄƾ֤²¢¼ì²éÆäȨÏÞ¡£GuardÀàÌṩÁ˼¸ÖÖÒªÁìÀ´¾ÙÐÐÉí·ÝÑéÖ¤ £¬ÀýÈçcheck()¡¢attempt()ºÍviaRemember()¡£

ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄÀý×Ó £¬Õ¹Ê¾ÁËÔõÑùÔÚLaravelÖÐʹÓÃGuard¾ÙÐÐÓû§Éí·ÝÑéÖ¤£º

use IlluminateSupportFacadesAuth;

if (Auth::guard('web')->attempt(['email' => $email, 'password' => $password])) {
    // Óû§ÒÑÑéÖ¤
} else {
    // Ñé֤ʧ°Ü
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄÀý×ÓÖÐ £¬ÎÒÃÇʹÓÃÁËAuthÃÅÃæºÍguardÒªÁìÀ´Ö¸¶¨ÎÒÃÇҪʹÓÃÄĸöGuard¾ÙÐÐÉí·ÝÑéÖ¤¡£È»ºó £¬ÎÒÃÇ¿ÉÒÔʹÓÃattemptÒªÁìÀ´¼ì²éÓû§ÌṩµÄƾ֤ÊÇ·ñÓÐÓá£ÈôÊÇÑéÖ¤ÀÖ³É £¬Ôò¸ÃÒªÁì·µ»Øtrue £¬²»È»·µ»Øfalse¡£

×ܽá

Laravel GuardÊÇÒ»ÖÖÇ¿Ê¢¶øÎÞаµÄÉí·ÝÑé֤ϵͳ £¬ËüÔÊÐíÎÒÃÇΪӦÓóÌÐòÖÎÀí¶à¸öÉí·ÝÑéÖ¤ºÍÊÚȨÁ÷³Ì £¬²¢ÎªÃ¿¸öÁ÷³ÌÌṩ²î±ðµÄ¿ØÖƺÍÖÎÀí¡£

±¾ÎÄÏÈÈÝÁËLaravel GuardµÄ»ù±¾¿´·¨ £¬²¢Ö¸µ¼Äú½¨ÉèеÄGuard¡£ÎÒÃÇ»¹Í¨¹ýʾÀýÑÝʾÁËÔõÑùÔÚLaravelÖÐʹÓÃGuard¾ÙÐÐÓû§Éí·ÝÑéÖ¤¡£ÏÖÔÚ £¬Äú¿ÉÒÔʹÓÃGuard±£»¤ÄúµÄWebÓ¦ÓóÌÐò £¬È·±£Ö»ÓÐÕýµ±µÄÓû§¿ÉÒÔ»á¼ûÓ¦ÓóÌÐòÖеÄÃô¸ÐÊý¾Ý¡£

ÒÔÉϾÍÊÇLaravel¿ª·¢£ºÔõÑùʹÓÃLaravel GuardÖÎÀíÓû§Éí·ÝÑéÖ¤£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ