Lal Kumar Rai
Lal Kumar Rai

Reputation: 343

Redirect to dashboard if user is loggedin in Laravel 4.2

class DashboardController extends BaseController {

protected $layout = "layouts.dashboard";
public function __construct(){

//$this->beforeFilter('csrf', array('on'=>'post'));
$this->beforeFilter('auth', array('only'=>array('getIndex')));

}
public function getIndex(){
     $this->layout->content= View::make('dashboard.index');
}



}

Above given code is my dashboardController. It is ok when i login and it redirects to dashboard. When the user is in dashboard, it means the user is authenticated. Now in the url bar, i hits the url of login. in my case it is

http://localhost:8000/users/login

now it redirects to login even the user is logged in. Now when i want to know how we can redirect to dashboard authomatically if the user is logged in. I am new to laravel 4.2. I hope you will guide me. Im lost in this section

Upvotes: 1

Views: 122

Answers (1)

mishad050
mishad050

Reputation: 448

You can try to put this into your getIndex() function:

if(Session::has('login_parameters')) return Redirect::to('foo/dashboard');

I use this code in Laravel 3, hopefully it works in laravel 4.2 as well.

Upvotes: 1

Related Questions