1

I have tried many ways to set cookie in browser but unable to do so.

My request from Frontend
$response = Http::post("http://127.0.0.1:8000/api/login",["email"=>$logindata['email'],
                                                                    "password"=>$logindata['password']]);


my response from backend
return response(['message'=>'user logged in'])->withCookie(cookie('user',Auth::user(),300));

I do get a cookie in response but it is not set in browser or stored

I have also tried:

private function getCookieDetails($token)
    {
        return [
            'name' => '_token',
            'value' => $token,
            'minutes' => 1440,
            'path' => '/',
            'domain' => '127.0.0.1:8090',
            // 'secure' => true, // for production
            'secure' => null, // for localhost
            'httponly' => true,
            'samesite' => true,
        ];
    }




 //return this on login
    $cookie = $this->getCookieDetails($accessToken);
                return response('cookie')->withCookie($cookie['name'], $cookie['value'], 
                                                      $cookie['minutes'], $cookie['path'], 
                                                      $cookie['domain'], $cookie['secure'], 
                                                      $cookie['httponly'], $cookie['samesite']);
Atul
  • 11
  • 1
  • Have a look at [https://stackoverflow.com/questions/45207485/how-to-set-and-get-cookie-in-laravel](https://stackoverflow.com/questions/45207485/how-to-set-and-get-cookie-in-laravel). – slp Mar 02 '21 at 06:20

0 Answers0