title: How to set a cookie on response in Laravel Lumen 8
body: <p>I'm currently building a REST API with Laravel Lumen 8. I want to set a cookie if the user logged in successfully. I saw that in the Lumen 5.1 docs there was a section that showed how to send a cookie with the response (<a href="https://lumen.laravel.com/docs/5.1/responses#attaching-cookies-to-responses" rel="nofollow noreferrer">https://lumen.laravel.com/docs/5.1/responses#attaching-cookies-to-responses</a>). But in the documentation for version 8 this section is missing. I also looked into the Laravel 8 docs (<a href="https://laravel.com/docs/8.x/responses#attaching-cookies-to-responses" rel="nofollow noreferrer">https://laravel.com/docs/8.x/responses#attaching-cookies-to-responses</a>) and tried the following things in my routes/web.php file:</p>
  <p><strong>Attempt 1</strong></p>
  <pre class="lang-php prettyprint-override"><code>$router-&gt;get('/test', function () {
      return response('Hello World')-&gt;cookie(
          'name', 'value', 60
      );
  });
  </code></pre>
  <p>But then I get the following error:</p>
  <blockquote>
  <p>Argument 1 passed to
  Symfony\Component\HttpFoundation\ResponseHeaderBag::setCookie() must
  be an instance of Symfony\Component\HttpFoundation\Cookie, string
  given</p>
  </blockquote>
  <p><strong>Attempt 2</strong></p>
  <pre class="lang-php prettyprint-override"><code>use Illuminate\Support\Facades\Cookie;
  
  $router-&gt;get('/test', function () {
      Cookie::queue('name', 'value', 60);
      return response('Hello World');
  });
  </code></pre>
  <blockquote>
  <p>Error message: Target class [cookie] does not exist.</p>
  </blockquote>
  <p><strong>Attempt 3</strong></p>
  <pre class="lang-php prettyprint-override"><code>$router-&gt;get('/test', function () {
      $cookie = cookie('name', 'value', 60);
      return response('Hello World')-&gt;cookie($cookie);
  });
  </code></pre>
  <p>Error message: Call to undefined function cookie()</p>
  <p><strong>Attempt 4</strong></p>
  <pre class="lang-php prettyprint-override"><code>use Symfony\Component\HttpFoundation\Cookie;
  $router-&gt;get('/test', function () {
      return response(null)-&gt;withCookie(new Cookie('name', 'value'));
  });
  </code></pre>
  <p>This solution works, but if i set the third parameter like this <code>new Cookie('name', 'value', 60)</code>, I don't get an error message but the cookie doesn't get set anymore.
  And I'm also a bit sceptical because I never saw this in any official docs but only in this stack overflow question: <a href="https://stackoverflow.com/questions/54819773/set-cookie-on-response-in-lumen-5-6">Set cookie on response in lumen 5.6</a>.</p>
  <p>These weren't the only things I tried but nothing worked so far. Setting a cookie should be such an easy thing but I just can't achieve it. I'm pretty new to Laravel/Lumen, has it something to do with the new Version 8? Or what else am I doing wrong?</p>