I only find information on how to save a session variable which works like this: $request->session()->put('key', 'value');
But how can I access the session in a blade view?
No, SESSION variables are on the server side so from the client's perspective, they cannot change them. That's one of the main reasons we use Sessions instead of cookies. Sessions are a simple way to store data for individual users against a unique session ID.
You can access a session variable's value by using the global variable $_SESSION. In the example stated below, you will create another session with a variable that stores your name. session_start();
The correct syntax for this is: Session::set('variableName', $value); For Laravel 5.4 and later, the correct method to use is put : Session::put('variableName', $value);
Just use session()
helper to read the data:
{{ session('key') }}
Or:
{{ request()->session()->get('key') }}
If you want to store something, do this:
@php(session(['key' => 'value']))
Its quite simple as core php, you can use its facade in blade or a method like,
{{Session::get('key')}}
Or by method like,
{{ session()->get('key') }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With