PHP Session handling • Needed to interface with an existing database table • Wanted a way to pull out users without a bunch of fuss. (I also wanted to use Eloquent outside of Laravel)
! class User extends Eloquent { protected $table = 'registrations'; protected $timestamps = false; ! public function isLoggedIn() { if ($session_logged_in = $_SESSION['session_logged_in']) { $session_id = $_SESSION['session_id']; $session_email = $_SESSION['session_email']; ! // Get the user with this email $user = User::whereEmail($session_email)->first(); ! return Session::whereUserId($user->id)->first(); } return false; } ! public function hasSession() { return $session = User::whereEmail($this->email) ->where('last_activity', '<', new DateTime) ->first(); } }