简体   繁体   English

将Laravel Auth与自定义视图一起使用

[英]Use Laravel Auth with custom view

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? 如何利用现有的Laravel身份验证功能使它正常工作? 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. 例如将Ajax请求发送到AuthController,然后在登录的情况下返回Auth::user()或将表单数据发送到auth/register路由。

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: 在您的模板中,使用blade ,您可以执行以下操作:

@if(Auth::check())
  {{-- Show logout button --}}
@else
  {{-- Show login form --}}
@endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM