Description
Core\Auth\User auth()
Using our auth() function will give you access to our core authentication class.
Examples
<?php
route('/foo', function() {
// Check if a user is logged in
if (auth()->isLoggedIn()) {
echo "Hello logged in user!";
}
// Check if the user is an admin
if (auth()->isAdmin()) {
echo "Hello Admin!";
}
});
route('/bar', function() {
// This will redirect the user if they are not logged in
auth()->membersOnly();
});
Methods
| Method | Description | Usage | Returns |
|---|---|---|---|
| isLoggedIn() | Check if a user is logged in or not. | if (auth()->isLoggedIn()) {
echo "Hello logged in user!";
}
| true if logged in, false if not |