last day (15 days later) » 

9:39 AM
0
A: How to set cookie in custom command and get it in middleware Laravel

Akhtar MunirI would think that you have already created a middleware, suppose CookieMiddlware. So inside CookieMiddlware there is a handle method. There try to dd($request);. For example: public function handle($request, Closure $next) { dd($request); //return $next($request); } Register your mid...

 
$cookies = array('testing' => 'sonam'); Getting only key in middleware with null +cookies: Symfony\Component\HttpFoundation\ParameterBag {#1130 #parameters: array:1 [ "testing" => null ] }
 
json_encode($cookies); your array and then try.
 
public static function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null) as mentioned, it must be type of array. That's why when encoding in JSON getting fatal error
 
I know but when you are setting your cookies then make it json_encode and while accessing make it json_decode.
 
No change, getting null only
 
9:39 AM
I have done it in this way just for testing and it works. See updated answer
If you are still getting null, then try to clear your cookies and then try again.
 
I am running custom artisan command through CLI, clear cache instead
 
if you are using laravel clear cache commands these are for the application cache.
Cookies are stored in browser, so you need to clear browser cache.
 
So does it work now ?
 
I am running artisan command from terminal
 
9:47 AM
what command are you running ? can you show
 
php artisan customCommandName
I am accessing controller from custom command file
through Route
so Route has middlerware
Where cookies are checked
 
I understand and I am doing it with tinker and direct middleware route, and it's working
both ways are working
and with json_encode the result is ...
 
ok
Thank you for your help
 
Okay welcome
 

last day (15 days later) »