Your login function looks messy! Simply use this
public function login()
{
$rules = array('email' => 'required|email','password' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('login')->withErrors($validator)->withInput(Input::except('password'));
} else {
$attempt = Auth::attempt(array('email' => Input::get('email') , 'password' => Input::get('password') ));
if($attempt) {
$occasions = Occasion::with('occasioncategory')->active()->latest()->take(8)->get();
return Redirect::to('/')
->with(array('message' => 'Successfully logged in!', 'flash_type' => 'success'))
->with(compact('ocassions'))
}
return Redirect::back()
->with(array('message' => 'Invalid credentials, please try again'))
->withInput();
}
}
You do not have to save User's info manually in a Session. You can access the info anytime anywhere in the entire application using the Auth::user() object. e.g Auth::user()->email returns the email of the logged in user.