尊龙凯时人生就是搏

laravelÔõôÉèÖÃÇëÇóÍ·

laravel ÊÇÒ»¸öÊ¢ÐÐµÄ php ¿ò¼Ü £¬ËüÌṩÁ˸»ºñµÄ¹¦Ð§ºÍÓÅÒìµÄÉè¼Æģʽ £¬À´×ÊÖúÎÒÃǹ¹½¨¸ßЧ¡¢¿Éά»¤µÄ web Ó¦ÓóÌÐò¡£ÔÚÏÖʵ¿ª·¢ÖÐ £¬ÓÐʱ¼äÎÒÃÇÐèÒªÔÚ laravel Ó¦ÓóÌÐòµÄÇëÇóÍ·ÖÐÉèÖÃһЩ×Ô½ç˵µÄÐÅÏ¢ £¬±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ laravel ÖÐÉèÖÃÇëÇóÍ·¡£

ʹÓà middleware ÉèÖÃÇëÇóÍ·

ÔÚ Laravel ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓà middleware ÖÐÐļþÀ´ÉèÖÃÇëÇóÍ·¡£ÔÚ Laravel Ó¦ÓóÌÐòÖÐ £¬middleware ÊÇÓÃÀ´´¦Àí HTTP ÇëÇóºÍÏìÓ¦µÄÀú³ÌÖеÄÒ»¸öÌØÊâ×é¼þ¡£Òò´Ë £¬Ê¹Óà middleware ÉèÖÃÇëÇóÍ·ÊÇÒ»¸öÓÅÒìµÄÑ¡Ôñ¡£

ÎÒÃÇ¿ÉÒÔʹÓà Laravel µÄ make:middleware ÏÂÁîÀ´½¨ÉèÒ»¸ö middleware£º

php artisan make:middleware SetCustomHeader

µÇ¼ºó¸´ÖÆ

ÔÚн¨ÉèµÄ SetCustomHeader ÀàÖÐ £¬ÎÒÃÇ¿ÉÒÔÔÚ handle ÒªÁìÖÐÌí¼ÓÎÒÃÇÐèÒªµÄÇëÇóÍ·ÐÅÏ¢£º

namespace App\Http\Middleware;

use Closure;

class SetCustomHeader
{
    public function handle($request, Closure $next)
    {
        $request->headers->set('Custom-Header', 'Custom Value');

        return $next($request);
    }
}

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖÐ £¬ÎÒÃÇʹÓà $request->headers->set() ÒªÁìÀ´ÉèÖÃÇëÇóÍ·ÐÅÏ¢¡£ÕâÀïµÄ Custom-Header ÊÇ×Ô½ç˵µÄÍ·ÐÅÏ¢Ãû³Æ £¬Custom Value ÊÇÎÒÃÇËùÉèÖõÄ×Ô½ç˵ֵ¡£

ÔÚÉèÖÃÍê middleware ºó £¬ÎÒÃÇ»¹ÐèÒª½«Æä×¢²áµ½Ó¦ÓóÌÐòµÄÈ«¾Ö middleware ÖС£ÔÚ app/Http/Kernel.php ÎļþÖÐ £¬ÖÐÐļþÊý×é $middlewareGroups ÖÐÌí¼ÓÎÒÃǵÄРmiddleware£º

protected $middlewareGroups = [
    'web' => [
        // other middleware
        \App\Http\Middleware\SetCustomHeader::class,
    ],

    // other middleware groups
];

µÇ¼ºó¸´ÖÆ

È»ºó £¬ÎÒÃǾͿÉÒÔ×îÏÈʹÓÃеÄ×Ô½ç˵ÇëÇóÍ·ÁË¡£

ʹÓÃÈ«¾Ö middleware ÉèÖÃÇëÇóÍ·

ÔÚ Laravel ÖÐ £¬ÎÒÃÇÒ²¿ÉÒÔʹÓÃÈ«¾Ö middleware À´ÉèÖÃÇëÇóÍ·¡£È«¾Ö middleware »áÔÚÿ¸öÇëÇó´¦ÀíÀú³ÌÖж¼±»Ö´ÐÐ £¬Òò´Ë £¬È«¾Ö middleware Ò²¿ÉÒÔºÜÀû±ãµØÉèÖÃÇëÇóÍ·ÐÅÏ¢¡£

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÔÚÓ¦ÓóÌÐòµÄÈ«¾Ö middleware ÖÐ×¢²áÒ»¸öÐ嵀 middleware£º

protected $middleware = [
    // other middleware
    \App\Http\Middleware\SetCustomHeader::class,
];

µÇ¼ºó¸´ÖÆ

È»ºó £¬ÎÒÃÇ¿ÉÒÔÏñÉÏÒ»½ÚÖÐÄÇÑù £¬ÔÚ middleware ÀàÖÐÉèÖÃ×Ô½ç˵ÇëÇóÍ·ÐÅÏ¢£º

namespace App\Http\Middleware;

use Closure;

class SetCustomHeader
{
    public function handle($request, Closure $next)
    {
        $request->headers->set('Custom-Header', 'Custom Value');

        return $next($request);
    }
}

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

×îºó £¬ÎÒÃÇ¿ÉÒÔÏñƽʱһÑùʹÓà Laravel µÄÇëÇóºÍÏìÓ¦¹¦Ð§ £¬ËüÃÇ»á°üÀ¨ÎÒÃǸոÕÉèÖõÄ×Ô½ç˵ÇëÇóÍ·¡£

×ܽá

ÔÚ±¾ÎÄÖÐ £¬ÎÒÃÇÏÈÈÝÁËÔõÑùÔÚ Laravel ÖÐÉèÖÃ×Ô½ç˵µÄÇëÇóÍ·ÐÅÏ¢¡£ÎÒÃÇ¿ÉÒÔʹÓà middleware »òÈ«¾Ö middleware À´ÊµÏÖÕâ¸ö¹¦Ð§¡£ÎÞÂÛÊÇÄÄÖÖ·½·¨ £¬ÉèÖÃÇëÇóÍ·ÐÅÏ¢¶¼ÊǺÜÊǼòÆӵġ£Í¨¹ýÉèÖÃ×Ô½ç˵µÄÇëÇóÍ·ÐÅÏ¢ £¬ÎÒÃÇ¿ÉÒÔΪӦÓóÌÐòÌí¼Ó¸ü¶àµÄ¹¦Ð§ºÍÌØÕ÷¡£

ÒÔÉϾÍÊÇlaravelÔõôÉèÖÃÇëÇóÍ·µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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