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

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大