title: I am stuck at Unable to set cookie or session Laravel
body: <p>None of the below methods is setting cookie. i tried defining the route in <code>Routes/api.php</code> also.And in case of session,<code>dd(session()-&gt;get('access_token'));</code> inside the <code>session_login()</code> method immaediately after setting session gives data.But in <code>index()</code> method, it gives null data. I am able to use the <code>Symfony\Component\HttpFoundation\Cookie</code> facade only, when using the direct facade <code>use cookie;</code> it shows error <code>undefined type</code>.So, i couldn't try the <code>cookie::queue()</code>similarly for session also, not able to try with <code>use session </code> facade. that's why i've commented it in the below code.How can i fix this? i've already gone through many links in internet. Any help is much appreciated.</p>
  <p><strong>controller</strong></p>
  <pre><code>use Symfony\Component\HttpFoundation\Cookie;
  //use Cookie;
  use Illuminate\Support\Facades\Session;
  //use Session;
  
  class AuthController extends Controller
  {
      public function getCookie(Request $request){
          $value = $request-&gt;cookie('access_token');
          return $value;
       }
        public function login(Request $request)
      {
         $response = new Response();
         $response-&gt;withCookie(cookie('access_token','abcd',60));
  
         //Cookie::queue('access_token','abcd',60);
  
        //Cookie::queue(Cookie::make('access_token','abcd',60));  --shows error Call to undefined method Symfony\Component\HttpFoundation\Cookie::queue() 
  
         return redirect('/getCookie');
      }
     public function session_login(Request $request)
       {
         session(['access_token'=&gt;$token]);
         return redirect('/');
       }
       public function index()
       {
         return session()-&gt;get('access_token');
       }
  }
  </code></pre>
  <p><strong>Routes/web.php</strong></p>
  <pre><code>Route::post('/signin', [AuthController::class,'login']);
  Route::get('/getCookie',[AuthController::class,'getCookie']);
  Route::get('/',[AuthController::class,'index']);
  </code></pre>
  <p><strong>Config/session.php</strong></p>
  <pre><code>&lt;?php
  
  use Illuminate\Support\Str;
  
  return [
  
      'driver' =&gt; env('SESSION_DRIVER', 'file'),
      'lifetime' =&gt; env('SESSION_LIFETIME', 120),
      'expire_on_close' =&gt; false,
      'encrypt' =&gt; false,
      'files' =&gt; storage_path('framework/sessions'),
      'connection' =&gt; env('SESSION_CONNECTION', null),
      'table' =&gt; 'sessions',
      'store' =&gt; env('SESSION_STORE', null),
      'lottery' =&gt; [2, 100],
      'cookie' =&gt; env(
          'SESSION_COOKIE',
          Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
      ),
      'path' =&gt; '/',
      'domain' =&gt; env('SESSION_DOMAIN', null),
      'secure' =&gt; env('SESSION_SECURE_COOKIE'),  //also tried adding false to this
      'http_only' =&gt; true,
      'same_site' =&gt; 'lax',
  ];
  </code></pre>
  <p><strong>.env file</strong></p>
  <pre><code>BROADCAST_DRIVER=log
  CACHE_DRIVER=file
  FILESYSTEM_DRIVER=local
  QUEUE_CONNECTION=sync
  SESSION_DRIVER=file       //tried changing this to database also
  SESSION_LIFETIME=120
  SESSION_DOMAIN=mydomain.com
  SESSION_SECURE_COOKIE=false
  </code></pre>