laravel之session
session(config/session.php)
2.1 laravel使用session有三种方法:
request类的session()方法
session()辅助函数
Session facade
2.2 使用
//路由加载session组件
Route::group(['middleware' => ['web']], function () {
Route::any('session1', ['uses'=>'StudentController@session1']);
Route::any('session2', ['uses'=>'StudentController@session2']);
});
//存取session
2.2.1 HTTP request session
$request->session()->put("key1",'wocalei');
echo $request->session()->get("key1");
2.2.2 session()辅助函数
session()->put('key2','value2');
echo session->get('key2');
2.2.3 \Illuminate\Support\Facades\Session
//判断session中是否存在某个key
Session::has('key')
//删除某个session下的key
Session::forget('key')
//删除所有session信息
Session::flush()
//session单个值操作
Session::put('key3','value3');
echo Session::get('key3','defaultVal');