0

In a laravel 8 project, if I use Illuminate\Support\Facades\Cookie::get() in boot method of service provider, it is returning encrypted string. But when I use Cookie::get() in blade view file, it is returning decrypted value as expected.

AppServiceProvider.php

dump(Cookie::get('app_language'); // returns "eyJpdiI6.....IifQ==" (encrypted value)

login.blade.php

dump(Cookie::get('app_language'); // returns "fr" (decrypted value)

I need the decrypted value in service provider.

Tariq Imtinan
  • 114
  • 1
  • 14

1 Answers1

0

The cookies are not decrypted before the service providers are ran, hence, you cannot do this without some custom code. This is why it does not work the way you wanted per default.

Give this a read, similar question with responses: Laravel cookie in serviceprovider not comparable

Stoff
  • 517
  • 6
  • 22