user6804254
user6804254

Reputation:

Passing cookie from controller to view in laravel

I have problem with getting cookie which I saved earlier. I want to pass it through controller to view. Here is my cookie saved in jQuery (it works, checked).

$('.wybierz').on('click',function(){

    var id = $(this).attr('name');

    Cookies.set('chosenComp', id);

    highlightChoice(id);
});

and here is my controller

public function index(Request $request){
    $cookie = Cookie::get('chosenComp');
    $actualComp = $cookie;
    $coms = DB::table('items')->get();
    $teams = DB::table('results')->get();
    return view('nowa_druzyna',['teams'=>$teams],['coms'=>$coms])->with('actualComp',$actualComp);
}

First of all I just wanted to try passing the cookie which is a number but it doesn't show. My view

<option selected class="showCurrentComp" id="">{{$actualComp}}</option>

Upvotes: 0

Views: 228

Answers (1)

Quezler
Quezler

Reputation: 2435

Javascript stores raw cookies, Laravel expects cookies to be encrypted, you can exempt your cookie from that in the EncryptCookies middleware

Upvotes: 1

Related Questions