In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to determine whether to log in or not". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The operating environment of this tutorial: windows7 system, Laravel6 version, Dell G3 computer.
Determine whether the current user is logged in (authenticated)
You can use Auth facade's check method to check whether the user is authenticated. If authenticated, true will be returned:
Use Illuminate\ Support\ Facades\ Auth;if (Auth::check ()) {/ / the user has logged in.}
Although you can use the check method to confirm that the user is authenticated, middleware is usually used to verify that the user has authenticated before allowing access to some of the routes / controllers that the user is allowed to access.
Expand knowledge:
Many applications need to be logged in before they can be operated. Laravel provides an auth tool to achieve user authentication. And there is a config/auth.php to configure the auth tool.
Let's take a look at the common methods of the auth tool:
Auth::check (); / / determine whether the current user is not logged in to Auth::guest (); / / determine whether the current user is not logged in, contrary to check (); / / default is `web`Auth:: user (); / / get the current authenticated user, a provider's model Auth::id () / / get the ID of the current authenticated user (error will be reported if not logged in) Auth::attempt (['email' = > $email,' password' = > $password], true); / / attempt to authenticate the user with the given information (the session will be started automatically after success). The first array is the authentication parameter, and the second parameter true is the 'remember me' function Auth::login (User::find (1), $remember = false). / / Log in to a specified user to the application. Generally, after the login parameters are passed, execute the login method to save session and other successful login operations Auth::logout (); / / enable the user to log out (clear the session). This is the end of the content of "laravel determines whether to log in". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.