if(Auth::isLoggedIn()){ // code to display restricted content }else{ header("Location: login.php"); //redirect user to log in page }
if(Auth::isLoggedIn()){ $user = Auth::getUser(); //get user details echo "Hello " . $user['username']; }else{ echo "Please log in to access this page"; }This code checks if the user is logged in, and if true, displays a personalized greeting with the user's username. This function is commonly used in web applications that require authentication to personalize the user experience. Package library: This code examples belong to Laravel Package Library.