Laravel can't read a “recently” created cookie2019 Community Moderator ElectionCan't set PHP cookie on the same pageSet and Check Cookie in the one response - LaravelHow do I set/unset a cookie with jQuery?Create, read, and erase cookies with jQueryLocal Storage vs Cookiescookie delete problemSet cookie and get cookie with JavaScriptLaravel Setting cookies with AjaxBest Practices for Custom Helpers in Laravel 5iframe not reading cookies in ChromeMany questions about using Laravel PassportCan't get Auth object and cookies by consuming my own Laravel API

What do you call someone who likes to pick fights?

Conservation of Mass and Energy

Why restrict private health insurance?

What can I do if someone tampers with my SSH public key?

Can one live in the U.S. and not use a credit card?

What is the generally accepted pronunciation of “topoi”?

Specifying a starting column with colortbl package and xcolor

What is this diamond of every day?

Professor forcing me to attend a conference, I can't afford even with 50% funding

Source permutation

School performs periodic password audits. Is my password compromised?

What problems would a superhuman have who's skin is constantly hot?

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

Having the player face themselves after the mid-game

Outlet with 3 sets of wires

Getting the || sign while using Kurier

Vocabulary for giving just numbers, not a full answer

What is Tony Stark injecting into himself in Iron Man 3?

How does Ehrenfest's theorem apply to the quantum harmonic oscillator?

Why is a very small peak with larger m/z not considered to be the molecular ion?

How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?

Is it possible to avoid unpacking when merging Association?

Does a difference of tense count as a difference of meaning in a minimal pair?

How can I manipulate the output of Information?



Laravel can't read a “recently” created cookie



2019 Community Moderator ElectionCan't set PHP cookie on the same pageSet and Check Cookie in the one response - LaravelHow do I set/unset a cookie with jQuery?Create, read, and erase cookies with jQueryLocal Storage vs Cookiescookie delete problemSet cookie and get cookie with JavaScriptLaravel Setting cookies with AjaxBest Practices for Custom Helpers in Laravel 5iframe not reading cookies in ChromeMany questions about using Laravel PassportCan't get Auth object and cookies by consuming my own Laravel API










0















I have a project who authenticate the user using cookies like token_ and refreshToken_, and a middleware who intercept my routes and verify if the user is logged or not.

In my middleware, when i need to renew the token_ I have the following code:



namespace AppHttpMiddlewareVerifyAccessToken

$cookie_name = "token_";
$cookie_value = $obj->access_token;
$expires_in = $obj->expires_in;
$time = time() + $expires_in; // 3600 = 1 hora
$path = "/";
$domain = env('COOKIE_DOMAIN');
setcookie($cookie_name, $cookie_value, $time, $path, $domain, false, true);

$cookie_name = "refreshToken_";
$cookie_value = $obj->refresh_token;
setcookie($cookie_name, $cookie_value, $time + 3600, $path, $domain, false, true);

return $next($request);


It works apparently fine, but the problem is:

After the middleware intercep my route and renew the cookie, the request proced to his controller, but there, I can't access the cookie using $_COOKIE['token_'] and I get an error, but if I look in the chrome's inspector, the cookie is there and reloading the page (F5) I can access the cookie in controller

Have a method for me access the cookie in controller without need to go to the view before?










share|improve this question







New contributor




ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Possible duplicate of Can't set PHP cookie on the same page

    – ceejayoz
    Mar 6 at 14:44











  • laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');

    – Mihai Crăiță
    Mar 6 at 14:45











  • See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…

    – ceejayoz
    Mar 6 at 14:45
















0















I have a project who authenticate the user using cookies like token_ and refreshToken_, and a middleware who intercept my routes and verify if the user is logged or not.

In my middleware, when i need to renew the token_ I have the following code:



namespace AppHttpMiddlewareVerifyAccessToken

$cookie_name = "token_";
$cookie_value = $obj->access_token;
$expires_in = $obj->expires_in;
$time = time() + $expires_in; // 3600 = 1 hora
$path = "/";
$domain = env('COOKIE_DOMAIN');
setcookie($cookie_name, $cookie_value, $time, $path, $domain, false, true);

$cookie_name = "refreshToken_";
$cookie_value = $obj->refresh_token;
setcookie($cookie_name, $cookie_value, $time + 3600, $path, $domain, false, true);

return $next($request);


It works apparently fine, but the problem is:

After the middleware intercep my route and renew the cookie, the request proced to his controller, but there, I can't access the cookie using $_COOKIE['token_'] and I get an error, but if I look in the chrome's inspector, the cookie is there and reloading the page (F5) I can access the cookie in controller

Have a method for me access the cookie in controller without need to go to the view before?










share|improve this question







New contributor




ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Possible duplicate of Can't set PHP cookie on the same page

    – ceejayoz
    Mar 6 at 14:44











  • laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');

    – Mihai Crăiță
    Mar 6 at 14:45











  • See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…

    – ceejayoz
    Mar 6 at 14:45














0












0








0








I have a project who authenticate the user using cookies like token_ and refreshToken_, and a middleware who intercept my routes and verify if the user is logged or not.

In my middleware, when i need to renew the token_ I have the following code:



namespace AppHttpMiddlewareVerifyAccessToken

$cookie_name = "token_";
$cookie_value = $obj->access_token;
$expires_in = $obj->expires_in;
$time = time() + $expires_in; // 3600 = 1 hora
$path = "/";
$domain = env('COOKIE_DOMAIN');
setcookie($cookie_name, $cookie_value, $time, $path, $domain, false, true);

$cookie_name = "refreshToken_";
$cookie_value = $obj->refresh_token;
setcookie($cookie_name, $cookie_value, $time + 3600, $path, $domain, false, true);

return $next($request);


It works apparently fine, but the problem is:

After the middleware intercep my route and renew the cookie, the request proced to his controller, but there, I can't access the cookie using $_COOKIE['token_'] and I get an error, but if I look in the chrome's inspector, the cookie is there and reloading the page (F5) I can access the cookie in controller

Have a method for me access the cookie in controller without need to go to the view before?










share|improve this question







New contributor




ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have a project who authenticate the user using cookies like token_ and refreshToken_, and a middleware who intercept my routes and verify if the user is logged or not.

In my middleware, when i need to renew the token_ I have the following code:



namespace AppHttpMiddlewareVerifyAccessToken

$cookie_name = "token_";
$cookie_value = $obj->access_token;
$expires_in = $obj->expires_in;
$time = time() + $expires_in; // 3600 = 1 hora
$path = "/";
$domain = env('COOKIE_DOMAIN');
setcookie($cookie_name, $cookie_value, $time, $path, $domain, false, true);

$cookie_name = "refreshToken_";
$cookie_value = $obj->refresh_token;
setcookie($cookie_name, $cookie_value, $time + 3600, $path, $domain, false, true);

return $next($request);


It works apparently fine, but the problem is:

After the middleware intercep my route and renew the cookie, the request proced to his controller, but there, I can't access the cookie using $_COOKIE['token_'] and I get an error, but if I look in the chrome's inspector, the cookie is there and reloading the page (F5) I can access the cookie in controller

Have a method for me access the cookie in controller without need to go to the view before?







laravel laravel-5 cookies






share|improve this question







New contributor




ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 6 at 14:40









ArthurUFArthurUF

31




31




New contributor




ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1





    Possible duplicate of Can't set PHP cookie on the same page

    – ceejayoz
    Mar 6 at 14:44











  • laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');

    – Mihai Crăiță
    Mar 6 at 14:45











  • See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…

    – ceejayoz
    Mar 6 at 14:45













  • 1





    Possible duplicate of Can't set PHP cookie on the same page

    – ceejayoz
    Mar 6 at 14:44











  • laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');

    – Mihai Crăiță
    Mar 6 at 14:45











  • See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…

    – ceejayoz
    Mar 6 at 14:45








1




1





Possible duplicate of Can't set PHP cookie on the same page

– ceejayoz
Mar 6 at 14:44





Possible duplicate of Can't set PHP cookie on the same page

– ceejayoz
Mar 6 at 14:44













laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');

– Mihai Crăiță
Mar 6 at 14:45





laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');

– Mihai Crăiță
Mar 6 at 14:45













See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…

– ceejayoz
Mar 6 at 14:45






See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…

– ceejayoz
Mar 6 at 14:45













2 Answers
2






active

oldest

votes


















0














To read the value of Cookie in Laravel, do you need to use:



$token = Cookie::queued('token_');
dd($token->getValue());



https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html






share|improve this answer























  • Thanks, it worked.

    – ArthurUF
    Mar 7 at 19:56


















0














Alright, with Cookie::queued('token_') I receive the following object, but when I try access the "value" using:



$token = Cookie::queued('token_');
dd($token->value);


I get that error:



Cannot access protected property SymfonyComponentHttpFoundationCookie::$value


How can I access the value?






share|improve this answer








New contributor




ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025690%2flaravel-cant-read-a-recently-created-cookie%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    To read the value of Cookie in Laravel, do you need to use:



    $token = Cookie::queued('token_');
    dd($token->getValue());



    https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html






    share|improve this answer























    • Thanks, it worked.

      – ArthurUF
      Mar 7 at 19:56















    0














    To read the value of Cookie in Laravel, do you need to use:



    $token = Cookie::queued('token_');
    dd($token->getValue());



    https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html






    share|improve this answer























    • Thanks, it worked.

      – ArthurUF
      Mar 7 at 19:56













    0












    0








    0







    To read the value of Cookie in Laravel, do you need to use:



    $token = Cookie::queued('token_');
    dd($token->getValue());



    https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html






    share|improve this answer













    To read the value of Cookie in Laravel, do you need to use:



    $token = Cookie::queued('token_');
    dd($token->getValue());



    https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 7 at 19:53









    Leo MoraesLeo Moraes

    16




    16












    • Thanks, it worked.

      – ArthurUF
      Mar 7 at 19:56

















    • Thanks, it worked.

      – ArthurUF
      Mar 7 at 19:56
















    Thanks, it worked.

    – ArthurUF
    Mar 7 at 19:56





    Thanks, it worked.

    – ArthurUF
    Mar 7 at 19:56













    0














    Alright, with Cookie::queued('token_') I receive the following object, but when I try access the "value" using:



    $token = Cookie::queued('token_');
    dd($token->value);


    I get that error:



    Cannot access protected property SymfonyComponentHttpFoundationCookie::$value


    How can I access the value?






    share|improve this answer








    New contributor




    ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0














      Alright, with Cookie::queued('token_') I receive the following object, but when I try access the "value" using:



      $token = Cookie::queued('token_');
      dd($token->value);


      I get that error:



      Cannot access protected property SymfonyComponentHttpFoundationCookie::$value


      How can I access the value?






      share|improve this answer








      New contributor




      ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        0












        0








        0







        Alright, with Cookie::queued('token_') I receive the following object, but when I try access the "value" using:



        $token = Cookie::queued('token_');
        dd($token->value);


        I get that error:



        Cannot access protected property SymfonyComponentHttpFoundationCookie::$value


        How can I access the value?






        share|improve this answer








        New contributor




        ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        Alright, with Cookie::queued('token_') I receive the following object, but when I try access the "value" using:



        $token = Cookie::queued('token_');
        dd($token->value);


        I get that error:



        Cannot access protected property SymfonyComponentHttpFoundationCookie::$value


        How can I access the value?







        share|improve this answer








        New contributor




        ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Mar 7 at 19:13









        ArthurUFArthurUF

        31




        31




        New contributor




        ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        ArthurUF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















            ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.












            ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.











            ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025690%2flaravel-cant-read-a-recently-created-cookie%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко