gpt4 book ai didi

Laravel 5.2 身份验证 - 如何在每个页面中显示登录用户名和注销链接?

转载 作者:行者123 更新时间:2023-12-01 08:26:10 25 4
gpt4 key购买 nike

Laravel 5.2 身份验证

我使用 Laravel 5.2 创建了一个新的身份验证脚手架

php artisan make:auth

一切正常,除了我在 route 登录后获得登录/注册链接

/

但是当我在路由中时,它会显示带有注销链接的用户名(这是我希望在每个页面中都有的)

/home

如何在每个页面中显示登录用户名和注销链接?

What I don't want when logged in

What I want when logged-in in every page

最佳答案

这是因为,您没有在 / 路由上使用 auth 中间件。在您的 routes.php 文件中,默认值为:

Route::get('/', function () {
return view('welcome');
});

尝试将此闭包移动到生成脚手架时添加的 web 中间件中。您的 routes.php 文件在完成后应如下所示:

<?php

/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

// Route::get('/', function () {
// return view('welcome');
// });

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/

Route::group(['middleware' => ['web']], function () {
//
});

Route::group(['middleware' => 'web'], function () {
Route::auth();

// Add this!
Route::get('/', function () {
return view('welcome');
});

Route::get('/home', 'HomeController@index');
});

关于Laravel 5.2 身份验证 - 如何在每个页面中显示登录用户名和注销链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34468455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com