Laravel 5.2认证 - 我怎么能显示用户名,并在每个页面中的注销链接登录? [英] Laravel 5.2 Authentication - How can I show logged in user's name and the logout link in every page?
问题描述
Laravel 5.2认证
我创建了一个新的认证脚手架Laravel 5.2使用
PHP工匠化妆:AUTH
一切都完美,除了我得到登录/注册链接甚至,当我在我的路线登录后
/
但它显示了一个注销链接的用户名(这是我想要什么,在每一页)当我在航线
/家
我该怎么让登录的用户名,并在每个页面中的注销链接?
这是因为,你不使用你的身份验证的中间件 /
路线。在你的 routes.php文件
文件的默认为是这样的:
路线::得到('/',函数(){
返回视图(欢迎);
});
尝试移动这个封闭到网站
中间件这是当你产生的脚手架增加。你的 routes.php文件
文件应该是这个样子的时候完成:
< PHP/ *
| ------------------------------------------------- -------------------------
| routes文件
| ------------------------------------------------- -------------------------
|
|在这里你会在应用程序中注册的所有航线。
|这是一件轻而易举的事。只需告诉Laravel应该作出回应的URI
|并给它的控制器时,请求URI打电话。
|
* ///路线::得到('/',函数(){
//返回视图(欢迎);
//});/ *
| ------------------------------------------------- -------------------------
|申请途径
| ------------------------------------------------- -------------------------
|
|这条路线小组网的中间件组适用于所有航线
|它包含。 网络中间件组是在HTTP中定义
|内核和包括会话状态,CSRF保护,等等。
|
* /路线::组(['中间件'=>'网络'],函数(){
//
});路线::组(['中间件'=>'网络'],函数(){
路线:: AUTH(); //添加这个!
路线::得到('/',函数(){
返回视图(欢迎);
}); 路线::得到('/家庭,HomeController的@指数');
});
Laravel 5.2 Authentication
I created a new authentication scaffolding in Laravel 5.2 using
php artisan make:auth
everything worked perfectly except I get Login/Register links even after logging in when I'm in route
/
but it shows the user's name with a logout link (which is what I want to have in every page) when I'm in route
/home
How can I show logged in user's name and the logout link in every page?
This is because, you are not using the auth middleware on you /
route. In your routes.php
file the default for this is:
Route::get('/', function () {
return view('welcome');
});
Try moving this closure into the web
middleware that was added in when you generated the scaffolding. Your routes.php
file should look something like this when complete:
<?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认证 - 我怎么能显示用户名,并在每个页面中的注销链接登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!