Skip to content
Examples and API calls for Laravel

Cookies ​

Use cookies to set up browser state or check values written by your application. Puth's core cookie helpers operate on raw values and work on pages, not iframe-scoped browsers.

Read and write cookies ​

Visit the target origin before reading its cookies. Pass an array of cookie definitions to $browser->setCookie(); include a URL or domain to identify where each cookie belongs.

php
$browser->visit('https://app.test');
$browser->setCookie([
    ['name' => 'preference', 'value' => 'dark', 'url' => 'https://app.test'],
]);
$cookie = $browser->getCookieByName('preference');

$browser->getCookieByName() returns the cookie object when it exists. Inspect that object for its value, domain and path.

Use Laravel's plain-cookie assertions for raw values set through $browser->setCookie():

php
$browser->assertHasPlainCookie('preference');
$browser->assertPlainCookieValue('preference', 'dark');

Laravel's encrypted-cookie helpers are described separately in Laravel cookies.

Remove a cookie for the current page:

php
$browser->deleteCookie('preference');
php
$browser->assertPlainCookieMissing('preference');

If a name exists under several domains or paths, pass cookie definitions with the matching domain/path to $browser->deleteCookie() instead of a name alone.