I am trying to implement a one-page application. I want it to resemble the design in the attached image, where the right box will host a login/register fragment if the user is not signed in but will update to a profile/logout once authenticated.
How can I leverage the existing Laravel authentication feature to get this to work? Something like sending an Ajax request to the AuthController and then return Auth::user()
in case of login or sending form data to the auth/register
route.
You can check if a user is authenticated with
if (Auth::check()) {
// The user is logged in...
}
In your template, using blade , you could do something like this:
@if(Auth::check())
{{-- Show logout button --}}
@else
{{-- Show login form --}}
@endif
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.