处理缩进
terranc
4年前
修改理由:
相关信息:
- 类型:文档文章
- 文章: Route
- 文档: 《Laravel 速查表(5.8)》
此投稿已在 4年前 合并。
内容修改:
Old | New | Differences |
---|---|---|
9 | 9 | ``` |
10 | 10 | Route::resource('posts','PostsController'); |
11 | 11 | // 资源路由器只允许指定动作通过 |
12 | ||
12 | Route::resource('photo', 'PhotoController',['only' => ['index', 'show']]); | |
13 | 13 | Route::resource('photo', 'PhotoController',['except' => ['update', 'destroy']]); |
14 | 14 | ``` |
15 | 15 | … | … |
37 | 37 | Route::patch('foo', function(){}); |
38 | 38 | Route::delete('foo', function(){}); |
39 | 39 | // RESTful 资源控制器 |
40 | ||
40 | Route::resource('foo', 'FooController'); | |
41 | 41 | // 为一个路由注册多种请求方式 |
42 | ||
42 | Route::match(['get', 'post'], '/', function(){}); | |
43 | 43 | ``` |
44 | 44 | |
45 | 45 | ### 安全路由 (TBD) | … | … |
52 | 52 | |
53 | 53 | ``` |
54 | 54 | Route::get('foo/{bar}', function($bar){}) |
55 | ||
55 | ->where('bar', '[0-9]+'); | |
56 | 56 | Route::get('foo/{bar}/{baz}', function($bar, $baz){}) |
57 | ||
57 | ->where(array('bar' => '[0-9]+', 'baz' => '[A-Za-z]')) | |
58 | 58 | |
59 | 59 | // 设置一个可跨路由使用的模式 |
60 | 60 | Route::pattern('bar', '[0-9]+') | … | … |
64 | 64 | |
65 | 65 | ``` |
66 | 66 | // 为路由指定 Middleware |
67 | ||
67 | Route::get('admin/profile', ['middleware' => 'auth', function(){}]); | |
68 | 68 | Route::get('admin/profile', function(){})->middleware('auth'); |
69 | 69 | ``` |
70 | 70 | … | … |
74 | 74 | Route::currentRouteName(); |
75 | 75 | Route::get('foo/bar', array('as' => 'foobar', function(){})); |
76 | 76 | Route::get('user/profile', [ |
77 | ||
77 | 'as' => 'profile', 'uses' => 'UserController@showProfile' | |
78 | 78 | ]); |
79 | 79 | Route::get('user/profile', 'UserController@showProfile')->name('profile'); |
80 | 80 | $url = route('profile'); | … | … |
86 | 86 | ``` |
87 | 87 | Route::group(['prefix' => 'admin'], function() |
88 | 88 | { |
89 | ||
90 | ||
91 | ||
89 | Route::get('users', function(){ | |
90 | return 'Matches The "/admin/users" URL'; | |
91 | }); | |
92 | 92 | }); |
93 | 93 | ``` |
94 | 94 | … | … |
96 | 96 | |
97 | 97 | ``` |
98 | 98 | // 此路由组将会传送 'Foo\Bar' 命名空间 |
99 | ||
99 | Route::group(array('namespace' => 'Foo\Bar'), function(){}) | |
100 | 100 | ``` |
101 | 101 | |
102 | 102 | ### 子域名路由 |
103 | 103 | |
104 | 104 | ``` |
105 | 105 | // {sub} 将在闭包中被忽略 |
106 | ||
106 | Route::group(array('domain' => '{sub}.example.com'), function(){}); | |
107 | 107 | ``` |