Skip to content

Commit

Permalink
[feat] routing with arrow functiomn
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysice committed Jan 5, 2022
1 parent 5ea032e commit b7ea5c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

---

__更新于 2021/12/31:现在有208个小提示,分成14类.
__更新于 2022/1/5:现在有209个小提示,分成14类.



Expand All @@ -18,7 +18,7 @@ __更新于 2021/12/31:现在有208个小提示,分成14类.
- [模型关联](#模型关联) (31 提示)
- [数据库迁移](#数据库迁移) (13 提示)
- [视图](#视图) (11 提示)
- [路由](#路由) (21 提示)
- [路由](#路由) (22 提示)
- [验证](#验证) (14 提示)
- [集合](#集合) (6 提示)
- [授权](#授权) (5 提示)
Expand Down Expand Up @@ -2160,6 +2160,7 @@ public function boot()
19. [为你的每个模型重写路由绑定解析器](#为你的每个模型重写路由绑定解析器)
20. [如果你需要一个公共URL但是你想让他们更安全](#如果你需要一个公共URL但是你想让他们更安全)
21. [在中间件中使用Gate](#在中间件中使用Gate)
22. [简单路由-使用箭头函数](#简单路由-使用箭头函数)

### 分组中的分组

Expand Down Expand Up @@ -2626,6 +2627,20 @@ Route::put('/post/{post}', function (Post $post) {
})->middleware('can:update,post');
```

### 简单路由-使用箭头函数
在路由中你可以使用PHP的箭头函数 而不需要用匿名函数。

要做到这一点 你可以使用 `fn() =>` 这样看起来更简单。

```php
// Instead of
Route::get('/example', function () {
return User::all();
});
// You can
Route::get('/example', fn () => User::all());
```

## 验证

⬆️ [回到顶部](#Laravel-编码技巧) ⬅️ [上一个 (路由)](#路由) ➡️ [下一个 (集合)](#集合)
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Hey, like these tips? Also check out my premium [Laravel courses](https://larave

---

__Update 31 **December** 2021__: Currently there are __208 tips__ divided into 14 sections.
__Update 5 **January** 2022__: Currently there are __209 tips__ divided into 14 sections.

## Table of Contents

- [DB Models and Eloquent](#db-models-and-eloquent) (56 tips)
- [Models Relations](#models-relations) (31 tips)
- [Migrations](#migrations) (13 tips)
- [Views](#views) (11 tips)
- [Routing](#routing) (21 tips)
- [Routing](#routing) (22 tips)
- [Validation](#validation) (14 tips)
- [Collections](#collections) (6 tips)
- [Auth](#auth) (5 tips)
Expand Down Expand Up @@ -2022,6 +2022,7 @@ Tip given by [@godismyjudge95](https://twitter.com/godismyjudge95/status/1448825
- [Override the route binding resolver for each of your models](#override-the-route-binding-resolver-for-each-of-your-models)
- [If you need public URL but you want them to be secured](#if-you-need-public-url-but-you-want-them-to-be-secured)
- [Using Gate in middleware method](#using-gate-in-middleware-method)
- [Simple route with arrow function](#simple-route-with-arrow-function)

### Route group within a group

Expand Down Expand Up @@ -2468,6 +2469,20 @@ Route::put('/post/{post}', function (Post $post) {
})->middleware('can:update,post');
```

### Simple route with arrow function
You can use php arrow function in routing, without having to use anonymous function.

To do this, you can use `fn() =>`, it looks easier.

```php
// Instead of
Route::get('/example', function () {
return User::all();
});
// You can
Route::get('/example', fn () => User::all());
```

## Validation

⬆️ [Go to top](#laravel-tips) ⬅️ [Previous (Routing)](#routing) ➡️ [Next (Collections)](#collections)
Expand Down

0 comments on commit b7ea5c1

Please sign in to comment.