laravel:接收请求参数(10.27.0)
一,相关文档:
https://learnku.com/docs/laravel/10.x/requests/14849#e16c06
二,php代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; class NewsController extends Controller { //获取请求参数 public function home(Request $request ){ //所有参数 $params = $request ->all(); #获取所有参数 //get方法 $name1 = $request ->get( 'name' ); //input方法 $name2 = $request ->input( 'name' ); //动态方法 $name3 = $request ->name; //从请求对象得到参数 $name4 = request()->get( 'name' ); return [ 'params' => $params , 'name1' => $name1 , 'name2' => $name2 , 'name3' => $name3 , 'name4' => $name4 , ]; } //得到url/host/ip等 public function req(Request $request ){ //url $url = $request ->url(); //fullUrl $fullUrl = $request ->fullUrl(); //host $host = $request ->host(); //method $method = $request ->method(); //ip $ip = $request ->ip(); //path $path = $request ->path(); return [ 'url' => $url , 'fullurl' => $fullUrl , 'host' => $host , 'method' => $method , 'ip' => $ip , 'path' => $path , ]; } } |
三,测试效果
说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/10/17/laravel-jie-shou-qing-qiu-can-shu-10-27/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
四,查看laravel框架的版本:
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan --version
Laravel Framework 10.27.0