Authenticate user with Blade?

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?

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

2 Likes

That’s very awesome, thanks for the reference.

This topic was automatically closed after 42 days. New replies are no longer allowed.