According to the official docs on cookies:
By default, all cookies generated by Laravel are encrypted and signed so that they can't be modified or read by the client. If you would like to disable encryption for a subset of cookies generated by your application, you may use the $except property of the App\Http\Middleware\EncryptCookies middleware, which is located in the app/Http/Middleware directory
In my controller that sends a response with cookies, I set a cookie with return response("Success", 200)->cookie('api_token', $api_token, 2, '/');
, where $api_token
is a string generated by Str::random(80)
. I have a route in web.php
that is protected by middleware that checks if the cookie is valid. However, using $request->cookie('api_token');
in the middleware returns nothing, but I have to make an exception in the EncryptCookies
for api_token
to make this work.
I'm not sure why my cookie isn't being encrypted, even if I use a laravel function to set it. Am I misunderstanding which cookies are "generated" by Laravel?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire