尊龙凯时人生就是博

ÔõÑùÔÚLaravel 5.4ÖÐʵÏÖÖÐÐļþÌøת

ÔÚlaravel 5.4֮ǰ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÖÐÐļþÀ´ÊµÏÖÌøת¹¦Ð§¡£¿ÉÊÇ£¬laravel 5.4ÖÐÐļþµÄʵÏÖ·½·¨ÓÐËù²î±ð¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÌÖÂÛÔõÑùÔÚlaravel 5.4ÖÐʵÏÖÖÐÐļþÌøת¡£

Ò»¡¢ÔÚLaravel 5.4ÖÐʵÏÖÖÐÐļþÌøת

ÔÚLaravel 5.4ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃredirect()º¯ÊýºÍwith()º¯ÊýÀ´ÊµÏÖÖÐÐļþÌøת¡£ÏÂÃæÎÒÃÇÀ´¿´Ò»¸öÀý×Ó£º

½¨ÉèÒ»¸öÈÕÖ¾ÖÐÐļþ

ÔÚapp/Http/MiddlewareĿ¼Ï£¬½¨ÉèÒ»¸öLogMiddleware.phpÎļþ£¬ÄÚÈÝÈçÏ£º

<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Log;

class LogMiddleware
{
    public function handle($request, Closure $next)
    {
        Log::info('LogMiddleware');
        return $next($request);
    }
}

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂ뽨ÉèÁËÒ»¸öÃûΪLogMiddlewareµÄÖÐÐļþ£¬ÔÚhandleº¯ÊýÖмͼÁËÒ»ÌõÈÕÖ¾¡£

½¨ÉèÒ»¸öÊÚȨÖÐÐļþ

ÔÚapp/Http/MiddlewareĿ¼Ï£¬½¨ÉèÒ»¸öAuthMiddleware.phpÎļþ£¬ÄÚÈÝÈçÏ£º

<?php namespace App\Http\Middleware;

use Closure;

class AuthMiddleware
{
    public function handle($request, Closure $next)
    {
        if (!auth()->check()) {
            return redirect('/login')-&gt;with('error', 'ÇëÏȵǼ£¡');
        }

        return $next($request);
    }
}

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂ뽨ÉèÁËÒ»¸öÃûΪAuthMiddlewareµÄÖÐÐļþ£¬ÔÚhandleº¯ÊýÖÐÅжÏÓû§ÊÇ·ñÒѵǼ£¬ÈôÊÇδµÇ¼£¬ÔòÌøתµ½µÇ¼ҳÃ棬²¢½«¹ýʧÐÅÏ¢ÉúÑĵ½sessionÖС£

½«ÖÐÐļþ×¢²áµ½Â·ÓÉÖÐ

ÔÚroutes/web.phpÎļþÖУ¬×¢²á·ÓɺÍÖÐÐļþ£¬´úÂëÈçÏ£º

Route::get('/dashboard', function () {
    return view('dashboard');
})-&gt;middleware([LogMiddleware::class, AuthMiddleware::class]);

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂ뽨ÉèÁËÒ»¸öÃûΪdashboardµÄ·ÓÉ£¬ÔÚdashboard·ÓÉÖУ¬Ê¹ÓÃÁËLogMiddlewareºÍAuthMiddlewareÖÐÐļþ¡£

ʵÏÖÖÐÐļþÌøת

Ö±½Ó»á¼ûhttp://yourdomain/dashboardÒ³Ãæʱ£¬½«»á×Ô¶¯Ìøתµ½http://yourdomain/login£¬²¢ÔÚsessionÖÐÉúÑÄÓйýʧÐÅÏ¢¡£

¶þ¡¢×ܽá

ÔÚLaravel 5.4ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃredirect()º¯ÊýºÍwith()º¯ÊýÀ´ÊµÏÖÖÐÐļþÌøת¡£Í¨¹ýÒÔÉÏ°ì·¨£¬ÎÒÃÇÀֳɵØʵÏÖÁËÒ»ÆäÖÐÐļþÌøת¹¦Ð§¡£Ï£Íû±¾ÎÄÄܶÔÄãÓÐËù×ÊÖú£¡

ÒÔÉϾÍÊÇÔõÑùÔÚLaravel 5.4ÖÐʵÏÖÖÐÐļþÌøתµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

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