lundi 19 octobre 2015

Laravel cookie in compose not readable

When accesing a cookie value in my compose function:

File: Providers/ViewComposerServiceProvicer.php

public function boot(Request $request) { $this->composeTopBar($request);}

public function composeTopBar(Request $request)
{
     $cookieValue = $request->cookie('brand');
    // if value not set use default value.
    if($cookieValue == null)
    {
        $cookieValue = 1;
    }
    $brands = \App\Brand::orderBy('priority', 'asc')->get();
    foreach($brands as $brand){
        if($brand->id == $cookieValue){
            $brand->menuActive = true;
        }
        else{
            // show value to debug
            $brand->menuActive = $cookieValue;
        }
    }


    view()->composer('front.layouts.top', function ($view) use ($brands) {
        $view->with('brandItems',$brands );
    });
}

the cookieValue looks like

yJpdiI6IlNJODBvQ1RNM004OWVleyJpdiI6IlNJODBvQ1RNM004OWVleyJpdiI6IlNJODBvQ1RNM004OWVl

While the value in my controller looks like '2' How can i get the original value 2 in my compose function?

I need to get the original value to compare it in my composeTopBar function so I can pass a variable to be true if it equals the cookie value.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire