-1

I need to read laravel cookies on api routes, but the middleware doesn't give me this option. When i read the cookie, it's encrypted. Can you help me telling how can I work with cookies on api side? I'm creating the cookie for the user on my controller like this

$cookieParams = cookie("params|{$campaign}", "{$campaign->id}{$utm_content}", 2628000);

Now I'm trying to read the cookie when I access an api route, on api.php

Route::get('/testando', 'API\Checkout\ApiCheckoutController@teste');

And the Controller

public function teste()
{

    # Verificamos cookies de campanha para o produto do checkout
    $cookie = Cookie::get("params|2920649");
    
    return $cookie;
}

And the return is encrypted

eyJpdiI6InYzeTQyelJ3N0VmY2JIeHJ6cXBBYkE9PSIsInZhbHVlIjoicnMyclloK29lNkhTNlIyaVdwZ2JNeVY0NHl1V1ZBdm5oZGM4bzczXC92dEhsOGRRRmI0V2ROMnNyOXFVQW5wZXNUeXdzNVNQRUJWYWtnMVZTVk9sVUdBPT0iLCJtYWMiOiI2ZjNlZDIzOGE5YTkyYmIzZTg3YTRkOGFlMjk1Mjc5OTMwYjU3MWNmZWI4Y2M3NjY2MDQ3YzE0MmM4ODY1MzkwIn0

PS: When I access an route from web.php the cookie works just fine, it's not encrypted.

1 Answers1

1

I solved the problem by using the web middleware inside api.php, like this:

Route::group(['middleware' => ['web']], function () {Route::get('/testando', 'API\Checkout\ApiCheckoutController@teste');});

As the web middleware has the AddQueuedCookiesToResponse class, I could read the cookie perfectly