---
title: "laravel 自定义 检查 session 数据是否存在"
author: "ww111"
date: "2016-03-03T18:05:46Z"
tags: []
categories: ["互联网"]
slug: "laravel-session"
draft: false
lastmod: "2016-03-04T12:06:53Z"
id: 2280334
url: "https://ww111.iteye.com/blog/2280334"
---

```
// vendor/laravel/framework/src/Illuminate/Session/Store.php
// 添加下面方法，然后在需要的地方，Session::hasSession()
     public function hasSession(){
         return $this->handler->read($this->getId()) ? true : false;
     }

//
 public function resetId($id)
    {
        $this->flush();
        $this->id = $id;
        if($this->hasSession()){
            $this->loadSession();
        }
   }
```