dongzhui2636 2015-01-05 15:39
浏览 29
已采纳

重定向无法在资源控制器中用于注销路由在Laravel中工作

These are my routes:

Route::get('login',  array('as' => 'login', 'uses' => 'SessionController@create'));
Route::get('logout', array('as' => 'logout', 'uses' => 'SessionController@destroy'));
Route::resource('sessions', 'SessionController', array('only' => array('create', 'store', 'destroy')));

Route::get('/', array('as' => 'home', function()
{
    return View::make('home');
}));

And this is my session controller:

<?php

use Latheesan\Repo\Session\SessionInterface;
use Latheesan\Service\Form\Login\LoginForm;

class SessionController extends \BaseController {

    protected $session;
    protected $loginForm;

    public function __construct(SessionInterface $session, LoginForm $loginForm)
    {
        $this->session = $session;
        $this->loginForm = $loginForm;
    }

    /**
     * Show the form for creating a new resource.
     * GET /sessions/create
     *
     * @return Response
     */
    public function create()
    {
        return View::make('sessions.create');
    }

    /**
     * Store a newly created resource in storage.
     * POST /sessions
     *
     * @return Response
     */
    public function store()
    {
        // snipped
    }

    /**
     * Remove the specified resource from storage.
     * DELETE /sessions
     *
     * @return Response
     */
    public function destroy()
    {
        // Logout user
        $this->session->destroy();

        // Fire user logout event
        Event::fire('user.logout');

        // Success
        Redirect::home();
    }

}

This is the contents of SentrySession - http://pastebin.com/d3ijZHQv

Now, when I go to the logout route (for e.g. http://my-site.com/logout), it appears to be logging me out however I am not being re-directed back to home page. I just see a blank white page.

If I add something like dd('here'); after the Redirect::home(); line, I can see the word, which means the re-direction is broken/not working.

Any idea why this might be and how to fix it?

I have the error reporting (E_ALL & display_errors) turned on and laravel.log file is empty.

  • 写回答

1条回答 默认 最新

  • doujiang2643 2015-01-05 15:59
    关注

    use this: return Redirect::home();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀