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();

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题