本文介绍了Laravel中未加密的Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要读取Laravel应用设置的JS中的cookie.有没有办法在Laravel中做到这一点(而不是直接通过PHP进行设置)而不覆盖类?

I need to read a cookie in JS set by my Laravel app. Is there a way to do this in Laravel (as opposed to setting it directly through PHP) without overriding classes?

推荐答案

请参见EncryptCookies中间件-这使您可以设置例外;即不加密的Cookie.

See the EncryptCookies Middleware - this allows you to set the exceptions; that is, cookies that are not to be encrypted.

namespace App\Http\Middleware;

use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;

class EncryptCookies extends BaseEncrypter
{
    /**
     * The names of the cookies that should not be encrypted.
     *
     * @var array
     */
    protected $except = [
        'my_cookie'
    ];
}

这篇关于Laravel中未加密的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 22:59
查看更多