Example
This can be used for many different things. For example, you could set a variable on the form success page if a user has filled out a special survey form.
{{ session:set entered_survey="true" }}
{{-- Using Antlers Blade Components --}}<s:session:set entered_survey="true" /> {{-- Using session() helper --}}@php(session()->put('entered_survey', true))
Later you could decide to show a message instead of the form if the user has already filled it out.
{{ session }} {{ if entered_survey }} <p>You already filled out the form.</p> {{ /if }}{{ /session }}
@if (session()->get('entered_survey')) <p>You already filled out the form.</p>@endif
Multiple Variables
You can set multiple variables at once and reference interpolated data (references to variables).
{{ session:set likes="hats" :visited="url" }}
{{-- Using Antlers Blade Components --}}<s:session:set likes="hats" :visited="url" />
Tag Pair
This tag is also available as a pair, which can be used to immediately display set data.
{{ session:set likes="boomboxes" }} <p>You like {{ likes }}, huh?</p>{{ /session:set }}
<s:session:set likes="boomboxes"> <p>You like {{ $likes }}, huh?</p></s:session:set>
Setting Array Data
Array data can be set with dot notation.
{{ session:set likes.books="true" likes.hats="true" }}
{{-- Using Antlers Blade Components --}}<s:session:set likes.books="true" likes.hats="true" />
Forgetting Data
Data can be removed from the session session:forget, and the entire session flushed with session:flush. 🚽