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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能