Roots Discourse

Authenticate user with Blade?


#1

Curious if there’s a better way to authenticate users using Blade.

The traditional way to check if a user is logged in or not to display certain information goes like this:

<?php if ( is_user_logged_in() ) { ?>You're logged in. Log out.<?php } ?>

Some Blade documentation suggests:

@if (Auth::check())
  //show logged in navbar 
@else
  //show logged out navbar
@endif

Or Blade 5.7+ suggests:

@auth
// The user is authenticated...
@endauth

@guest
// The user is not authenticated...
@endguest

Perhpas these methods aren’t configured with Sage to work with WordPress? Or are there other suggestions better than all I listed?


#2

Not all parts of Blade are in Sage, like the ones you’ve listed.

Checkout @Log1x sage-directives package which has something similar: https://github.com/Log1x/sage-directives/blob/master/README.md#user


#3

That’s very awesome, thanks for the reference.