×ðÁú¿­Ê±

ÔõÑùʹÓÃLaravelʵÏֵǼ²¢¾ÙÐÐÌøת

laravelÊÇÒ»¿î¹ãÊܽӴýµÄphp¿ª·¢¿ò¼Ü £¬Ëü¾ßÓÐÒ×ÓÚѧϰ¡¢¸ßЧ¿ª·¢¡¢Çå¾²Îȹ̵ÈÌصã £¬±»Öڶ࿪·¢ÕßËùϲ»¶¡£ÔÚlaravelÖÐ £¬µÇ¼ºÍÌøתÊǷǾ­³£¼ûµÄ²Ù×÷ £¬ÎÒÃÇ¿ÉÒÔºÜÇáËɵØʵÏÖÕâЩ¹¦Ð§¡£

µÇ¼¹¦Ð§ÊÇÍøÕ¾±Ø²»¿ÉÉٵĹ¦Ð§Ö®Ò» £¬Ëü¿ÉÒÔΪÓû§Ìṩ˽ÈË¿Õ¼ä £¬ÒÔ¼°¸ü¸ß¼¶±ðµÄ»á¼ûȨÏÞ¡£ÔÚLaravelÖÐ £¬ÎÒÃÇ¿ÉÒÔÇáËɵØʵÏֵǼ¹¦Ð§¡£ÔÚÕâÀï £¬ÎÒÃǽ«Ì½ÌÖÔõÑùʹÓÃLaravelʵÏֵǼ²¢¾ÙÐÐÌøת¡£

½¨ÉèÓû§ÈÏ֤ϵͳ

Ê×ÏÈ £¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÓû§ÈÏ֤ϵͳ¡£LaravelÒѾ­ÎªÎÒÃÇÌṩÁËÒ»¸öÏֳɵÄÈÏ֤ϵͳ £¬ÎÒÃÇÖ»ÐèÒªÔËÐÐÒÔÏÂÏÂÁî¼´¿É£º

php artisan make:auth

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁ×Ô¶¯ÌìÉúµÇ¼¡¢×¢²á¡¢ÒÅÍüÃÜÂëµÈ¹¦Ð§ £¬Í¬Ê±ÌìÉúÏìÓ¦µÄÊÓͼºÍ¿ØÖÆÆ÷¹©ÎÒÃÇʹÓá£

½¨ÉèloginÊÓͼ

½ÓÏÂÀ´ £¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÓÃÓڵǼµÄÊÓͼ¡£ÎÒÃÇ¿ÉÒÔʹÓÃLaravelÌṩµÄÄ£°åÒýÇæBladeÀ´ÊµÏÖÊÓͼµÄ½¨Éè¡£ÔÚresources/views/authÎļþ¼ÐϽ¨ÉèÒ»¸ölogin.blade.phpµÄÎļþ £¬´úÂëÈçÏ£º

@extends('layouts.app')

@section('content')

<div>
    <div>
        <div>
            <div>
                <div>{{ __('Login') }}</div>

                <div>
                    <form>
                        @csrf

                        <div>
                            <label>{{ __('E-Mail Address') }}</label>

                            <div>
                                <input>

                                @error('email')
                                    <span>
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div>
                            <label>{{ __('Password') }}</label>

                            <div>
                                <input>

                                @error('password')
                                    <span>
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div>
                            <div>
                                <div>
                                    <input>

                                    <label>
                                        {{ __('Remember Me') }}
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div>
                            <div>
                                <button>
                                    {{ __('Login') }}
                                </button>

                                @if (Route::has('password.request'))
                                    <a>
                                        {{ __('Forgot Your Password?') }}
                                    </a>
                                @endif
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

µÇ¼ºó¸´ÖÆ

ÔÚ¸ÃÊÓͼÖÐ £¬ÎÒÃÇʹÓÃÁËBootstrapµÄÑùʽ £¬²¢ÇÒʹÓÃÁËLaravelÌṩµÄ±íµ¥ÌìÉúº¯ÊýÀ´ÌìÉú±íµ¥¡£³ý´ËÖ®Íâ £¬ÎÒÃÇ»¹ÔÚ±íµ¥ÖÐÌí¼ÓÁË@csrfÖ¸Áî £¬ÓÃÓÚ±ÜÃâ¿çÕ¾µãÇëÇóαÔ죨CSRF£©¹¥»÷¡£

´¦Öóͷ£µÇ¼ÇëÇó

µÇ¼±íµ¥½¨ÉèºÃÖ®ºó £¬ÎÒÃÇ»¹ÐèÒª¶ÔµÇ¼ÇëÇó¾ÙÐд¦Öóͷ£¡£ÎÒÃÇ¿ÉÒÔÔÚAuth\LoginControllerÀàÖÐ £¬Ê¹ÓÃLaravelÌṩµÄauthenticate£¨£©ÒªÁìÀ´ÑéÖ¤Óû§µÄÈÏÖ¤ÐÅÏ¢¡£ÈôÊÇÑéÖ¤ÀÖ³É £¬ÎÒÃÇ¿ÉÒÔͨ¹ýLaravelµÄredirect£¨£©ÒªÁìÀ´¾ÙÐÐÌøת¡£

´úÂëÈçÏ£º

public function authenticate(Request $request)
{
    $credentials = $request-&gt;only('email', 'password');

    if (Auth::attempt($credentials)) {
        // ÈÏ֤ͨ¹ý£¬Ìøתµ½Ö¸¶¨Ò³Ãæ
        return redirect()-&gt;intended('dashboard');
    }
    else {
        // ÈÏ֤ʧ°Ü£¬Ìøתµ½µÇ¼ҳÃæ
        return redirect()-&gt;route('login')-&gt;with('error', 'Invalid credentials');
    }
}

µÇ¼ºó¸´ÖÆ

ÔڸôúÂëÖÐ £¬ÎÒÃÇʹÓÃÁËAuth::attempt()ÒªÁìÀ´¶ÔÓû§µÄÊäÈë¾ÙÐÐÑéÖ¤¡£

ÈôÊÇÑé֤ͨ¹ý £¬ÎÒÃÇ¿ÉÒÔʹÓÃLaravelµÄintended£¨£©ÒªÁìÀ´¾ÙÐÐÌøת¡£¸ÃÒªÁ콫×Ô¶¯Ìøתµ½Óû§ÏëÒª»á¼ûµÄÒ³Ãæ £¬ÈôÊÇÓû§Ã»ÓÐÖ¸¶¨ £¬ÔòĬÈÏÌøתµ½¡°dashboard¡±Ò³Ãæ¡£

ÈôÊÇÈÏ֤ʧ°Ü £¬ÔòʹÓÃLaravelµÄredirect£¨£©ÒªÁ콫Óû§ÖØÐÂÌøתµ½µÇ¼ҳÃæ £¬²¢ÔÚÌøתʱת´ï¹ýʧÐÂÎÅ¡£

Ìøתµ½Ö¸¶¨Ò³Ãæ

ÔÚLaravelÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃlaravelÖеÄRedirectÀàºÍURLÀàÀ´¾ÙÐÐÌøת¡£ÈôÊÇÎÒÃÇÒªÖض¨Ïòµ½Â·ÓÉ £¬Ôò¿ÉÒÔʹÓÃLaravelµÄredirect£¨£©ÒªÁì¡£ÈôÊÇÎÒÃÇÒªÖض¨Ïòµ½URL £¬Ôò¿ÉÒÔʹÓÃLaravelµÄURL::to£¨£©ÒªÁì¡£

´úÂëʾÀýÈçÏ£º

// Öض¨Ïòµ½Â·ÓÉ
return redirect()-&gt;route('dashboard');

// Öض¨Ïòµ½URL
return redirect(URL::to('/dashboard'));

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀú³ÌÖÐ £¬Çë¼Ç×Å £¬Äã¿ÉÒÔÔÚ¿ØÖÆÆ÷»ò·ÓÉÎļþÖÐ×ÔÓÉʹÓÃÉÏÊöÌøתҪÁì £¬ÒÔ±ãÌøתµ½×¼È·µÄÒ³Ãæ¡£

½áÂÛ

Laravel ÊÇÒ»¸ö¹¦Ð§Ç¿Ê¢ÇÒÒ×ÓÚʹÓÃµÄ PHP ¿ò¼Ü £¬ËüÌṩÁËÐí¶à¹¤¾ßºÍ¹¦Ð§À´¼ò»¯ Web ¿ª·¢¡£ÔÚÕâƪÎÄÕÂÖÐ £¬ÎÒÃǽÌÊÚÁËÔõÑùÔÚLaravelÖÐʵÏÖÓû§µÇ¼ºÍÌøתµ½Ö¸¶¨Ò³ÃæµÄÀú³Ì¡£

ÎÒÃÇÊ×ÏȽ¨ÉèÁËÒ»¸öÓû§ÈÏ֤ϵͳ £¬È»ºó½¨ÉèÁ˵Ǽ±íµ¥¡¢´¦Öóͷ£µÇ¼ÇëÇó¡¢ÒÔ¼°Ê¹ÓÃRedirectÀàºÍURLÀà¾ÙÐÐÌøתµÄ´úÂë¡£ÕâЩÊÖÒÕºÍÒªÁì¿ÉÒÔ×ÊÖú¿ª·¢Ö°Ô±¿ìËÙʵÏÖÇ¿Ê¢µÄµÇ¼ºÍÌøת¹¦Ð§¡£

ͬʱֵµÃ×¢ÖصÄÊÇ £¬Çå¾²ÎȹÌÐÔÓÀÔ¶ÊÇÒ»¸öºÜÊÇÖ÷ÒªµÄÎÊÌâ £¬ÎÒÃÇÐèҪȷ±£´úÂë¿â¾­ÓÉÑÏ¿á²âÊÔ²¢Óë×îеÄÇå¾²±ê×¼Ïà·ûÒÔ¼á³ÖϵͳµÄÎȹÌÐÔºÍÇå¾²ÐÔ¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃLaravelʵÏֵǼ²¢¾ÙÐÐÌøתµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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