1. 程式人生 > >laravel表單操作

laravel表單操作

$request->all()//獲取所有引數
if($request->isMethod('GET'))
{
判斷是否是GET請求
}
$res = $request->is('student/*');
$res = $request->ajax();
========================================================

laravel 使用 session 路由配置
Route::group(['middleware'=>['web']],function (){
Route::any('session1',['uses'=>'[email protected]

']);
Route::any('session2',['uses'=>'[email protected]']);
});

StudentController 內 存入session
Session存入陣列內方法
Sssion::push('key','value1');
Sssion::push('key','value2');
取出Session中的陣列並且刪除
Session::pull('key');

判斷Session中某個Key在不在
Session::has('key')
public function session1(Request $request)
{
//HTTP request session();
$request->session()->put('key1','val1');
Session::put('key','value');
}

StudentController 內 讀取 session
public function session2(Request $request)
{
$session = $request->session()->get('key1');
Session::get('key','如果key不存在可以在這裡寫預設值');
var_dump($session);
}

php變數轉json
public function response()
{
$data = ['errCode'=>0,
'errMsg'=>'success',
'data'=>'dada'
];
return response()->json($data);
}