Can I access gatekeeper from any view?
Closed this issue · 1 comments
Herikle commented
I know that it's not a forum here. But I need help and I can't find any solution on documentation. I can't check, for example, if a user is logged in a view?
{% if(isLoggedIn()) %}
<h1> I can't do that </h1>
{% endif %}
in laravel i have
@if (Auth::check())
<h1> I can do that </h1>
@endif
freost commented
You have to assign the gatekeeper object to your views.
// Assign it to the view you're rendering
$this->view->render('my-view', ['gatekeeper' => $this->gatekeeper]);
// Assign it globally to all views
// (this can be done in a base controller or in the bootstrap file).
$this->view->assign('gatekeeper', $this->gatekeeper);
You can also install the helpers
package and access the gatekeeper instance like this:
{% if(gatekeeper()-> isLoggedIn()) %}
I'm logged in!
{% endif %}