Get cookie in the Laravel 5 constructor

get the encrypted value of Cookie in the construction method. How to convert it to unencrypted value

public function __construct()
{
    echo Cookie::get("customer_id");
    // 
    // eyJpdiI6Im5NZVNkTnpJSlFib3BpXC91VmdHWFJ....
}

public function index()
{
    echo Cookie::get("customer_id");
    // 
    // 6
}
Dec.10,2021

  

similar problems were encountered in a 5.4 project. At that time, I just used Laravel, to find that I could not get the content by using the session-related method in the construction method, but I could do it in the method. Later, after consulting the relevant website, I learned about it. Because the controller constructor runtime middleware is not ready, the content cannot be fetched. The solution is to manually load middleware

Menu