總結laravel中$request獲取請求信息用法

下面由laravel教程欄目給大家總結laravel中$request獲取請求信息用法?,希望對需要的朋友有所幫助!

總結laravel中$request獲取請求信息用法

laravel中$request可用的一些方法小結
1,請求方法的獲取

$method?=?$request->method();

2,檢測請求方法

$res?=?$request->isMethod('post')

3,獲取請求的路徑

$path?=?$request->path()

4,獲取完整的url

$url?=?$request->url();

5,獲取請求的ip

$ip?=?$request->ip()

6,獲取端口

$port?=?$request->getPort();

7,參數的獲取

$name?=?$request->input('name')

8,設置默認值

$res?=?$request->input('name','10')

9,檢測請求參數

$res?=?$request->has('name')

10,獲取所有請求參數

$res?=?$request->all()

11,提取部分參數

$res?=?$request->only(['username','password'])

12,剔除不需要的參數

$res?=?$request->except(['username','password'])

13,獲取請求頭信息

$res?=?$request->header('Connection')

14,檢測文件是否有上傳

$res?=?$request->hasFile('cover')

15,提取上傳的文件

$res?=?$request->file('file');

16,獲取Cookie

$cookies?=?$request->cookie();

17,新增cookie值

$response->withCookie(cookie('cookie','learn-laravel',3));?? //第一個參數是cookie名,第二個參數是cookie值,第三個參數是有效期(分鐘). $response->withCookie(cookie()->forever('cookie-name','cookie-value'));

?

以上就是總結

? 版權聲明
THE END
喜歡就支持一下吧
點贊11 分享