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

ÔõÑùʹÓÃ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
ÍøÕ¾µØͼ