laravel get cookie decoded value
In web request context cookies are usually automatically encrypted and
decrypted by the EncryptCookies middleware. So easiest option would be just to
enable this middleware (and its enabled by default in Laravel).
If you need to decrypt any value manually, the following will do the trick:
// get the encrypter service
$encrypter = app(\Illuminate\Contracts\Encryption\Encrypter::class);
// decrypt
$decryptedString = $encrypter->decrypt($encryptedString);
Check the code of the EncryptCookies middleware to learn more about what it
does internally.
############### Or Other Method ########################
By default Crypt::decrypt tries to deserialize the value, and yours is not
serialized and thats why you get the error. You need to pass a second argument
like:
Crypt::decrypt(Cookie::get('userId'), false);