Latheesan
Latheesan

Reputation: 24116

Redirection not working in Laravel from resourceful controller for logout route

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.

Upvotes: 0

Views: 166

Answers (1)

Maximilian Prepl
Maximilian Prepl

Reputation: 412

use this: return Redirect::home();

Upvotes: 1

Related Questions