doukuang1897 2017-02-10 08:55
浏览 70
已采纳

即使登录后,Laravel也会重定向到每个页面上登录

I'm having problems with Laravel since i removed Entrust.

Everything was working fine until i tried installing Entrust. I removed it because it kept saying the following message the same as this question Laravel cache store does not support tagging

Laravel cache store does not support tagging

I removed everything to do with Entrust and removed any changes I had to make but since then whenever I try to go to another page after logging in, it redirects back to the login page. I log back in and it redirects to the dashboard as it should but as soon as i go to another page, it redirects me back to login again.

Any ideas how to fix this?

UPDATE

I think i've narrowed down to the problem.

I created a new project and started again. I created the Auth, created a couple test controllers and views.

I logged in as normal and I got redirected to the Home contoller. I then went to another page and it loaded fine as it should. The views are using the default layout in views/layouts/app.blade.php. As soon as I change it to a custom layout the problem occurs again but is okay if i change it back to app.blade.php

Here is my new default.blade.php but i don't see why this doesn't work anymore

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>@yield('title')</title>
    <link rel="icon" type="image/png" href="public/css/favicon-32x32.png" sizes="32x32">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css">
    {{ HTML::style('css/bootstrap.css') }}
    @if (!empty($styles))
    @foreach($styles as $style)
    {{ HTML::style($style . '.css') }}
    @endforeach
    @endif
    {{ HTML::style('css/app.css') }}
    {{ HTML::style('css/media.css') }}
</head>
<body class="{{ $body_class or '' }}">
<div class="wrapper">
    @include('layouts.header')
    @yield('content')
    <div class="push"></div>
</div>
<div class="footer navbar-primary">
    <div class="row">
        <div class="col-xs-12">
            <footer>
                <p>&copy; Copyright @php echo date('Y'); @endphp Axminster Tools &amp; Machinery</p>
            </footer>
        </div>
    </div>
</div>
<script>
    window.website_url = '{{ URL::to('/') }}';
</script>
{{ HTML::script('assets/src/jquery/dist/jquery.min.js') }}
{{ HTML::script('assets/src/jquery-ui/jquery-ui.min.js') }}
{{ HTML::script('js/bootstrap.min.js') }}
{{ HTML::script('js/validate.js') }}

@if(isset($jsVars))
<script>
    @foreach($jsVars as $key => $val)
    var {{ $key }} = {{ $val }};
    @endforeach
</script>
@endif
<script>
    $(function() {
        $("#searchform").submit(function(e) {
            $("#searchform").attr("action", "/search/term/" + encodeURI($("#keywords").val()));
        });
    });
</script>
@if (!empty($scripts))
@foreach($scripts as $script)
{{ HTML::script($script . '.js') }}
@endforeach
@endif
</body>
</html>
  • 写回答

1条回答 默认 最新

  • duanlie7962 2017-02-13 09:28
    关注

    I eventually found the problem.

    After doing a new installation i tested the Auth and it worked. As soon as I copied across some of my template files I found the problem occurred again. After looking at the template layout files, I found I was using this for the logout link

    <a href="{{ Auth::logout() }}">Change password</a>
    

    I did this within the first few days of learning Laravel and it was never a problem before...don't know why.

    I changed it to this and it all works as expected

    <a href="{{ url('/logout') }}" onclick="event.preventDefault(); document.getElementById('logout-form').submit();">Logout</a>
    <form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
          {{ csrf_field() }}
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog