Laravel在刷新时查看@include自动注销

时间:2018-02-01 11:12:37

标签: php laravel session laravel-5 laravel-blade

我正在使用Laravel 5.5和mysql数据库,会话存储在数据库中。

@Problem:每当我刷新或进入另一个页面时,它都会将我注销并将我重定向回登录页面。

@Cause:调试后,每当我在名为top.blade.php的视图模板中@include视图master.blade.php时,我就会发现,当我刷新页面时,它会自动让我退出并杀掉会议。

top.blade.php内的代码:

  

<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">

  <!-- Mobile Menu -->
  <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>

  <!-- Header Icon -->
    <a  href="{{ url('/') }}">
      <img class="navbar-brand" src="{{ asset('images/head.png') }}" alt="Little Project">
    </a>

    <!-- Message Of The Day -->
    <div class="navbar-text visible-xs"><p>Little Project</p></div>
    {{ Auth::user()}} <!-- to check the user info if it retains -->
</div>



<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

<!--Right side of the NavBar -->
  <ul class="nav navbar-nav navbar-right">
      @guest
        <li><a href="{{ route('login') }}">Login</a></li>
        <li><a href="{{ route('register') }}">Register</a></li>
      @else
        <li><a href="{{ route('home') }}">Demo</a></li>
        <li><a href="{{ Auth::logout() }}">Logout</a></li>
      @endguest
  </ul>

</div><!-- /.navbar-collapse -->

master.blade.php文件是

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>

<!--meta header-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">

    <!-- Title -->
    <title>Little Project</title>
</head>
<body>
    @include('constants.top')
    <div class="container">
      <!-- Contents -->
      @yield('content')

    </div>


    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}"></script>
</body>

</html>

Upon login, successful display of information at both top.blade.php and master.blade.php to check the User's login information

然而,当刷新时,只要我@include top.blade.php

,它就会销毁所有会话

2 个答案:

答案 0 :(得分:0)

我发现了我的问题,

我的<li><a href="{{ Auth::logout() }}">Logout</a></li>文件中有top.blade.php,每次加载页面时都会自动调出注销。 糟糕的做法!!

应该做的是使用logout controller

将帖子方法定向到csrf_field()表单

答案 1 :(得分:-1)

确保您使用web中间件组作为路由。并确保web中的app/Http/Kernel.php中间件组包含\Illuminate\Session\Middleware\StartSession::class,