I want to show a modal only once, this could probably be achieved with cookies but I don't know how to do this:
what I want to do is in my blade template check if cookie "modal" is set, if it's set I don't show the modal and if it's not set I show the modal and set cookie to true?
This is what I came up with so far:
@if ($modal->isActive && Cookie::get('cookie_modal') !== null )
<!--cookie is set, don't show modal-->
@elseif ($modal->isActive && Cookie::get('cookie_modal') == null )
<!--show_modal and set cookie to true so that next time modal doesn't show up-->
{{Cookie::make('cookie_modal', true, 60) }}
<div id="modal" style="width:100%; height:500px; position:relative; background-color:red; margin:25px auto;"></div>
@endif
</div>
What you really want is session()->flash('key', value)
So it would end up being:
@if ($modal->isActive && session()->has('key'))
If you need more strict comparison, you can compare the flashed value:
&& session()->get('key') === $value
flash
only works for the next request. A subsequent request, or reload, would not trigger this (unless the controller serving the view re-flashes the session data)