Search code examples
phplaravelsessionlaravel-8laravel-session

How to determine session value at Controller


I have set a session value like this at Blade:

@php
if(...){
    Session::put('sent','city')
}else{
    Session::put('sent','country')
}
@endphp

And now, I need to check the sent session value at the Controller but don't know how...

So if you know, please help me out.

Thanks.


Solution

  • Same as you are doing for inserting the value (documentation):

    public class SomeController{
      public function some_method(){
        $value = session()->get('sent');
        // or if you are not certain that the value is being set
        $value = session()->get('sent', 'default_value');
      }
    }