doukuang1897
2017-02-10 08:55 阅读 53
已采纳

即使登录后,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 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>
    
    点赞 评论 复制链接分享

相关推荐