Home > database >  Can't set cookies in Laravel
Can't set cookies in Laravel

Time:06-13

I thought cookies were simple, but I'm struggling with them for quite a while.

I'm trying to create cookies with the information and it does not work. It looks like the creation is not successful.

use Illuminate\Support\Facades\Cookie;

Cookie::queue( Cookie::make('test', 'my test token', 5563));

I'm running laravel application on localhost as http://localhost:8000/ or http://127.0.0.1:8000/ I read about issues with chrome and tried FF and Edge still do not understand where is the problem. Do I need to change to URL to localhost.com?

CodePudding user response:

Cookie::queue in Laravel only actually sends the queued cookie(s) if you issue a Laravel response of some kind. If you do your own responding (print "OK"; sort of stuff) instead of using something like return response() or return redirect() or return view(), the cookie will be queued but never sent.

CodePudding user response:

try it with

Cookie::queue('cookie_key', "Cookie value", 150);

I still use this method often for my site https://sita.app/

Php 7.4 and laravel ^8.82.

I run on macosx operating system with command php artisan serve to activate server with domain http://127.0.0.1:8000

And running on windows with vhost sita.localhost all works fine

  • Related