简体   繁体   English

Laravel 5.7制作Auth

[英]Laravel 5.7 making Auth

I have some issue about Laravel Auth. 我对Laravel Auth有一些问题。 I already make my own page with Laravel and now I want to add user login. 我已经在Laravel上创建了自己的页面,现在我想添加用户登录名。 So I used php artisan make:auth and it went smoothly but. 因此,我使用了php artisan make:auth ,但是运行顺利。 My auth doesn't show up on my index page. 我的身份验证未显示在索引页面上。 I think, it's because I already change Laravel's main page. 我认为,这是因为我已经更改了Laravel的主页。 And now, how can I display it on my own main page. 现在,如何在自己的主页上显示它。

So Laravel Auth came with the Home Controller and with Route in web file. 因此,Laravel Auth随Home Controller和Web文件中的Route一起提供。 I already changed it to my main page which is welcome.blade but still can not see login and register bar at right top? 我已经将其更改为主页welcome.blade,但仍无法在右上方看到登录和注册栏?

Controller 调节器

public function index()
    {
        return view('welcome');
    }

Route 路线

Route::get('welcome', 'HomeController@index')->name('welcome');

How can I call it Auth's register and login link to my main mage(welcome.blade)? 如何称呼我的主法师(welcome.blade)的身份验证的注册和登录链接?

welcome.blade welcome.blade

<div class="flex-center position-ref full-height">
          @if (Route::has('login'))
              <div class="top-right links">
                  @auth
                      <a href="{{ url('welcome') }}">Home</a>
                  @else
                      <a href="{{ route('login') }}">Login</a>

                      @if (Route::has('register'))
                          <a href="{{ route('register') }}">Register</a>
                      @endif
                  @endauth
              </div>
          @endif
      </div>

I am calling on page with the code above. 我使用上面的代码在页面上调用。 But doesn't work? 但是不行吗?

You should try this: 您应该尝试这样:

Route::group( ['middleware' => 'auth' ], function()
{
     Route::get('welcome', 'HomeController@index')->name('welcome');
});



Route::get('login', 'LoginController@showLogin')->name('login');
Route::get('register', 'RegisterController@register')->name('register');

If you want it only single routes. 如果只需要一条路线。 Just chain middleware('auth') at the end of your route. 只需在路线的末尾链接中间件('auth')。 Example: 例:

Route::get('welcome', 'HomeController@index')->name('welcome')->middleware('auth');

You can customize it. 您可以自定义它。

You can group your routes with this middleware as suggested by saurabh dhariwal 您可以按照saurabh dhariwal的建议,使用此中间件对路线进行分组

On your edit. 在您编辑。 Make a route. 制定路线。 And on that route controller return the view of your register page and login page. 然后在该路由控制器上返回您的注册页面和登录页面的视图。 Simple as that 就那么简单

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

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