Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 703 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to set cookies in laravel 5 independently inside controller

#1
I want to set cookies in Laravel 5 independently

i.e., Don't want to use

`return response($content)->withCookie(cookie('name', 'value'));`

I just want to set cookie in some page and retrieve in some other page


Creation can be like this

`$cookie = Cookie::make('name', 'value', 60);`

But how can i retrieve those cookies in some controller itself ?
Reply

#2
You may try this:

Cookie::queue($name, $value, $minutes);

This will queue the cookie to use it later and later it will be added with the response when response is ready to be sent. You may [check the documentation][1] on `Laravel` website.

Update (`Retrieving A Cookie Value`):

$value = Cookie::get('name');


----------


*Note: If you set a cookie in the current request then you'll be able to retrieve it on the next subsequent request.*


[1]:

[To see links please register here]

Reply

#3
You are going right way my friend.Now if you want retrive `cookie` anywhere in project just put this code `$val = Cookie::get('COOKIE_NAME');`
That's it!
[For more information how can this done click here][1]


[1]:

[To see links please register here]

Reply

#4
If you want to set cookie and get it outside of request, Laravel is not your friend.

Laravel cookies are part of Request, so if you want to do this outside of Request object, use good 'ole PHP setcookie(..) and $_COOKIE to get it.
Reply

#5
Here is a sample code with explanation.

//Create a response instance
$response = new Illuminate\Http\Response('Hello World');

//Call the withCookie() method with the response method
$response->withCookie(cookie('name', 'value', $minutes));

//return the response
return $response;
Cookie can be set forever by using the forever method as shown in the below code.

$response->withCookie(cookie()->forever('name', 'value'));

<h1>Retrieving a Cookie</h1>

//’name’ is the name of the cookie to retrieve the value of
$value = $request->cookie('name');
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through