set cookie in laravel 5.4

Viewed 195

I am trying to set few cookie variables and redirect to next route.

    $inputParams = [];

    $inputParams['show_match_skus'] = $this->request->input('show_match_skus');
    $inputParams['show_all'] = $this->request->input('show_all');
    $inputParams['prevent_dialog'] = $this->request->input('prevent_dialog');

    $inputParams = array_map(array($this, 'sanitizeInputParams'), $inputParams);
    $filterArr = array_filter($inputParams);

    if(count($filterArr) > 0) {
        if(array_key_exists('show_match_skus', $filterArr)) {
            $cookie_sku_match = Cookie::make('show_match_skus', true);                
        }
        if(array_key_exists('show_all', $filterArr)) {
            $cookie_all = Cookie::make('show_all', true);
        }
        if(array_key_exists('prevent_dialog', $filterArr)) {
            $cookie_prevent = Cookie::make('prevent_dialog', true);
        }

    }
    //dd(Cookie::get());
    //dd(Cookie::get('show_all'));
    return redirect()->route('list');

After creating cookies I need to redirect to list route.

But on checking in browser, I get none.

Also Cookie::get() displays only XSRF-TOKEN and laravel_session.

But Cookie::get('show_all') shows the cookie.

What am I doing wrong?

0 Answers
Related