abort函数翻译没对

修改理由:
相关信息:
- 类型:文档文章
- 文章: 辅助函数
- 文档: 《Laravel 10 中文文档(10.x)》
此投稿由 MArtian 在 1年前 合并。
标题修改:
内容修改:
Old | New | Differences |
---|---|---|
1 | ||
2 | 1 | # 辅助函数 |
3 | 2 | |
4 | 3 | - [简介](#introduction) | … | … |
95 | 94 | |
96 | 95 | </div> |
97 | 96 | |
98 | ||
99 | ||
97 | ||
98 | ||
100 | 99 | <a name="strings-method-list"></a> |
101 | 100 | ### 字符串 |
102 | 101 | … | … |
269 | 268 | |
270 | 269 | </div> |
271 | 270 | |
272 | ||
273 | ||
271 | ||
272 | ||
274 | 273 | <a name="urls-method-list"></a> |
275 | 274 | ### URLs |
276 | 275 | … | … |
402 | 401 | // ['name' => 'Desk', 'price' => 100] |
403 | 402 | |
404 | 403 | |
405 | ||
406 | ||
404 | ||
405 | ||
407 | 406 | <a name="method-array-collapse"></a> |
408 | 407 | #### `Arr::collapse()` {.collection-method} |
409 | 408 | … | … |
505 | 504 | // false |
506 | 505 | |
507 | 506 | <a name="method-array-first"></a> |
508 | ||
509 | ||
507 | ||
508 | ||
510 | 509 | #### `Arr::first()` {.collection-method} |
511 | 510 | |
512 | 511 | `Arr::first` 函数返回数组中满足指定条件的第一个元素: | … | … |
591 | 590 | |
592 | 591 | // false |
593 | 592 | |
594 | ||
595 | ||
593 | ||
594 | ||
596 | 595 | <a name="method-array-hasany"></a> |
597 | 596 | #### `Arr::hasAny()` {.collection-method} |
598 | 597 | … | … |
682 | 681 | ] |
683 | 682 | */ |
684 | 683 | |
685 | ||
686 | ||
684 | ||
685 | ||
687 | 686 | <a name="method-array-last"></a> |
688 | 687 | #### `Arr::last()` {.collection-method} |
689 | 688 | … | … |
758 | 757 | // [1 => 'Taylor', 2 => 'Abigail'] |
759 | 758 | |
760 | 759 | <a name="method-array-prepend"></a> |
761 | ||
762 | ||
760 | ||
761 | ||
763 | 762 | <a name="method-array-last"></a> |
764 | 763 | #### `Arr::last()` {.collection-method} |
765 | 764 | … | … |
834 | 833 | // [1 => 'Taylor', 2 => 'Abigail'] |
835 | 834 | |
836 | 835 | <a name="method-array-prepend"></a> |
837 | ||
838 | ||
836 | ||
837 | ||
839 | 838 | #### `Arr::prepend()` {.collection-method} |
840 | 839 | |
841 | 840 | `Arr::prepend` 函数将一个值插入到数组的开始位置: | … | … |
940 | 939 | |
941 | 940 | // [2, 5] - (retrieved randomly) |
942 | 941 | |
943 | ||
944 | ||
942 | ||
943 | ||
945 | 944 | <a name="method-array-set"></a> |
946 | 945 | #### `Arr::set()` {.collection-method} |
947 | 946 | … | … |
1059 | 1058 | ] |
1060 | 1059 | */ |
1061 | 1060 | |
1062 | ||
1063 | ||
1061 | ||
1062 | ||
1064 | 1063 | <a name="method-array-to-css-classes"></a> |
1065 | 1064 | #### `Arr::toCssClasses()` {.collection-method} |
1066 | 1065 | … | … |
1138 | 1137 | |
1139 | 1138 | // ['Laravel'] |
1140 | 1139 | |
1141 | ||
1142 | ||
1140 | ||
1141 | ||
1143 | 1142 | 如果给定值是 `null` ,将返回一个空数组: |
1144 | 1143 | |
1145 | 1144 | use Illuminate\Support\Arr; | … | … |
1242 | 1241 | ] |
1243 | 1242 | */ |
1244 | 1243 | |
1245 | ||
1246 | ||
1244 | ||
1245 | ||
1247 | 1246 | 通常情况下,已存在的值将会被覆盖。如果只是希望设置一个目前不存在的值,你可以增加一个 `false` 作为函数的第四个参数: |
1248 | 1247 | |
1249 | 1248 | $data = ['products' => ['desk' => ['price' => 100]]]; | … | … |
1305 | 1304 | $path = config_path('app.php'); |
1306 | 1305 | |
1307 | 1306 | <a name="method-database-path"></a> |
1308 | ||
1309 | ||
1307 | ||
1308 | ||
1310 | 1309 | #### `database_path()` {.collection-method} |
1311 | 1310 | |
1312 | 1311 | `database_path` 函数返回 `database` 目录的完整路径。你可以使用 `database_path` 函数来生成数据库目录下指定文件的完整路径: | … | … |
1352 | 1351 | |
1353 | 1352 | $path = resource_path('sass/app.scss'); |
1354 | 1353 | |
1355 | ||
1356 | ||
1354 | ||
1355 | ||
1357 | 1356 | <a name="method-storage-path"></a> |
1358 | 1357 | #### `storage_path()` |
1359 | 1358 | … | … |
1417 | 1416 | |
1418 | 1417 | // ' my name' |
1419 | 1418 | |
1420 | ||
1421 | ||
1419 | ||
1420 | ||
1422 | 1421 | <a name="method-str-after-last"></a> |
1423 | 1422 | #### `Str::afterLast()` |
1424 | 1423 | … | … |
1496 | 1495 | |
1497 | 1496 | // fooBar |
1498 | 1497 | |
1499 | ||
1500 | ||
1498 | ||
1499 | ||
1501 | 1500 | <a name="method-str-contains"></a> |
1502 | 1501 | #### `Str::contains()` |
1503 | 1502 | … | … |
1566 | 1565 | |
1567 | 1566 | `radius` 选项默认为 `100`,允许你定义应出现在截断字符串前后的字符数。 |
1568 | 1567 | |
1569 | ||
1570 | ||
1568 | ||
1569 | ||
1571 | 1570 | 此外,你可以使用`omission`选项来定义将附加到截断字符串的字符串: |
1572 | 1571 | |
1573 | 1572 | use Illuminate\Support\Str; | … | … |
1650 | 1649 | |
1651 | 1650 | // false |
1652 | 1651 | |
1653 | ||
1654 | ||
1652 | ||
1653 | ||
1655 | 1654 | <a name="method-str-is-json"></a> |
1656 | 1655 | #### `Str::isJson()` {.collection-method} |
1657 | 1656 | … | … |
1745 | 1744 | |
1746 | 1745 | // 敏捷的棕色狐狸... |
1747 | 1746 | |
1748 | ||
1749 | ||
1747 | ||
1748 | ||
1750 | 1749 | 你也可通过第三个参数来改变追加到末尾的字符串: |
1751 | 1750 | |
1752 | 1751 | use Illuminate\Support\Str; | … | … |
1809 | 1808 | |
1810 | 1809 | return (string) Str::orderedUuid(); |
1811 | 1810 | |
1812 | ||
1813 | ||
1811 | ||
1812 | ||
1814 | 1813 | <a name="method-str-padboth"></a> |
1815 | 1814 | #### `Str::padBoth()` {.collection-method} |
1816 | 1815 | … | … |
1886 | 1885 | |
1887 | 1886 | // children |
1888 | 1887 | |
1889 | ||
1890 | ||
1888 | ||
1889 | ||
1891 | 1890 | 你可以提供一个整数作为函数的第二个参数来检索字符串的单数或复数形式: |
1892 | 1891 | |
1893 | 1892 | use Illuminate\Support\Str; | … | … |
1964 | 1963 | |
1965 | 1964 | // Laravel 9.x |
1966 | 1965 | |
1967 | ||
1968 | ||
1966 | ||
1967 | ||
1969 | 1968 | <a name="method-str-replace-array"></a> |
1970 | 1969 | #### `Str::replaceArray()` {.collection-method} |
1971 | 1970 | … | … |
2039 | 2038 | |
2040 | 2039 | // laravel-5-framework |
2041 | 2040 | |
2042 | ||
2043 | ||
2041 | ||
2042 | ||
2044 | 2043 | <a name="method-snake-case"></a> |
2045 | 2044 | #### `Str::snake()` {.collection-method} |
2046 | 2045 | … | … |
2121 | 2120 | |
2122 | 2121 | // Laravel |
2123 | 2122 | |
2124 | ||
2125 | ||
2123 | ||
2124 | ||
2126 | 2125 | <a name="method-str-substrcount"></a> |
2127 | 2126 | #### `Str::substrCount()` {.collection-method} |
2128 | 2127 | … | … |
2192 | 2191 | |
2193 | 2192 | // Foo bar |
2194 | 2193 | |
2195 | ||
2196 | ||
2194 | ||
2195 | ||
2197 | 2196 | <a name="method-str-ucsplit"></a> |
2198 | 2197 | #### `Str::ucsplit()` {.collection-method} |
2199 | 2198 | … | … |
2273 | 2272 | |
2274 | 2273 | // 'foo_bar' |
2275 | 2274 | |
2276 | ||
2277 | ||
2275 | ||
2276 | ||
2278 | 2277 | <a name="method-trans"></a> |
2279 | 2278 | #### `trans()` {.collection-method} |
2280 | 2279 | … | … |
2320 | 2319 | |
2321 | 2320 | // 'Controller' |
2322 | 2321 | |
2323 | ||
2324 | ||
2322 | ||
2323 | ||
2325 | 2324 | <a name="method-fluent-str-append"></a> |
2326 | 2325 | #### `append` {.collection-method} |
2327 | 2326 | … | … |
2407 | 2406 | |
2408 | 2407 | // 'a' |
2409 | 2408 | |
2410 | ||
2411 | ||
2409 | ||
2410 | ||
2412 | 2411 | <a name="method-fluent-str-camel"></a> |
2413 | 2412 | #### `camel` {.collection-method} |
2414 | 2413 | … | … |
2493 | 2492 | |
2494 | 2493 | // '...is my na...' |
2495 | 2494 | |
2496 | ||
2497 | ||
2495 | ||
2496 | ||
2498 | 2497 | `radius` 选项默认为 `100`,允许你定义应出现在截断字符串每一侧的字符数。 |
2499 | 2498 | |
2500 | 2499 | 此外,还可以使用 `omission` 选项更改将添加到截断字符串之前和附加的字符串 | … | … |
2567 | 2566 | |
2568 | 2567 | // this/string/ |
2569 | 2568 | |
2570 | ||
2571 | ||
2569 | ||
2570 | ||
2572 | 2571 | <a name="method-fluent-str-headline"></a> |
2573 | 2572 | #### `headline` {.collection-method} |
2574 | 2573 | … | … |
2655 | 2654 | |
2656 | 2655 | // true |
2657 | 2656 | |
2658 | ||
2659 | ||
2657 | ||
2658 | ||
2660 | 2659 | <a name="method-fluent-str-is-json"></a> |
2661 | 2660 | #### `isJson` {.collection-method} |
2662 | 2661 | … | … |
2751 | 2750 | |
2752 | 2751 | // The quick brown fox... |
2753 | 2752 | |
2754 | ||
2755 | ||
2753 | ||
2754 | ||
2756 | 2755 | 你也可以通过第二个参数来改变追加到末尾的字符串: |
2757 | 2756 | |
2758 | 2757 | use Illuminate\Support\Str; | … | … |
2825 | 2824 | |
2826 | 2825 | // tayl**********.com |
2827 | 2826 | |
2828 | ||
2829 | ||
2827 | ||
2828 | ||
2830 | 2829 | <a name="method-fluent-str-match"></a> |
2831 | 2830 | #### `match` |
2832 | 2831 | … | … |
2905 | 2904 | |
2906 | 2905 | // ' James ' |
2907 | 2906 | |
2908 | ||
2909 | ||
2907 | ||
2908 | ||
2910 | 2909 | <a name="method-fluent-str-padleft"></a> |
2911 | 2910 | #### `padLeft` |
2912 | 2911 | … | … |
2983 | 2982 | |
2984 | 2983 | // child |
2985 | 2984 | |
2986 | ||
2987 | ||
2985 | ||
2986 | ||
2988 | 2987 | <a name="method-fluent-str-prepend"></a> |
2989 | 2988 | #### `prepend` |
2990 | 2989 | … | … |
3055 | 3054 | |
3056 | 3055 | // the quick brown fox jumps over a lazy dog |
3057 | 3056 | |
3058 | ||
3059 | ||
3057 | ||
3058 | ||
3060 | 3059 | <a name="method-fluent-str-replace-matches"></a> |
3061 | 3060 | #### `replaceMatches` |
3062 | 3061 | … | … |
3120 | 3119 | |
3121 | 3120 | // child |
3122 | 3121 | |
3123 | ||
3124 | ||
3122 | ||
3123 | ||
3125 | 3124 | <a name="method-fluent-str-slug"></a> |
3126 | 3125 | #### `slug` {.collection-method} |
3127 | 3126 | … | … |
3203 | 3202 | |
3204 | 3203 | // FooBar |
3205 | 3204 | |
3206 | ||
3207 | ||
3205 | ||
3206 | ||
3208 | 3207 | <a name="method-fluent-str-substr"></a> |
3209 | 3208 | #### `substr` {.collection-method} |
3210 | 3209 | … | … |
3268 | 3267 | // LARAVEL FRAMEWORK |
3269 | 3268 | |
3270 | 3269 | <a name="method-fluent-str-test"></a> |
3271 | ||
3272 | ||
3270 | ||
3271 | ||
3273 | 3272 | #### `test` {.collection-method} |
3274 | 3273 | |
3275 | 3274 | `test` 方法确定字符串是否与给定的正则表达式模式匹配: | … | … |
3355 | 3354 | // 'Taylor Otwell' |
3356 | 3355 | 如果需要,可以将另一个闭包作为第三个参数传递给 `when` 方法。如果条件参数的计算结果为 `false`,则将执行此闭包。 |
3357 | 3356 | |
3358 | ||
3359 | ||
3357 | ||
3358 | ||
3360 | 3359 | <a name="method-fluent-str-when-contains"></a> |
3361 | 3360 | #### `whenContains` {.collection-method} |
3362 | 3361 | … | … |
3416 | 3415 | |
3417 | 3416 | // 'Laravel' |
3418 | 3417 | |
3419 | ||
3420 | ||
3418 | ||
3419 | ||
3421 | 3420 | <a name="method-fluent-str-when-not-empty"></a> |
3422 | 3421 | #### `whenNotEmpty` {.collection-method} |
3423 | 3422 | … | … |
3488 | 3487 | |
3489 | 3488 | // 'Framework' |
3490 | 3489 | |
3491 | ||
3492 | ||
3490 | ||
3491 | ||
3493 | 3492 | <a name="method-fluent-str-when-is"></a> |
3494 | 3493 | #### `whenIs` {.collection-method} |
3495 | 3494 | … | … |
3559 | 3558 | |
3560 | 3559 | // 'Laravel Framework' |
3561 | 3560 | |
3562 | ||
3563 | ||
3561 | ||
3562 | ||
3564 | 3563 | <a name="method-fluent-str-word-count"></a> |
3565 | 3564 | #### `wordCount` {.collection-method} |
3566 | 3565 | … | … |
3623 | 3622 | |
3624 | 3623 | $url = route('route.name', ['id' => 1]); |
3625 | 3624 | |
3626 | ||
3627 | ||
3625 | ||
3626 | ||
3628 | 3627 | 默认情况下,`route` 函数会生成一个绝对路径的 URL。 如果想生成一个相对路径 URL,你可以传递 `false` 作为函数的第三个参数: |
3629 | 3628 | |
3630 | 3629 | $url = route('route.name', ['id' => 1], false); | … | … |
3674 | 3673 | $previous = url()->previous(); |
3675 | 3674 | |
3676 | 3675 | <a name="miscellaneous"></a> |
3677 | ## | |
3676 | ## 杂项 | |
3678 | 3677 | |
3679 | 3678 | <a name="method-abort"></a> |
3680 | 3679 | #### `abort()` {.collection-method} |
3681 | 3680 | |
3682 | ||
3681 | 使用`abort` 函数抛出一个[HTTP 异常](/docs/laravel/10.x/errors#http-exceptions)交给[异常处理](/docs/laravel/10.x/errors#the-exception-handler "异常处理程序") | |
3683 | 3682 | |
3684 | 3683 | abort(403); |
3685 | 3684 | |
3686 | ||
3687 | ||
3685 | ||
3686 | ||
3688 | 3687 | 你还可以提供应发送到浏览器的异常消息和自定义 HTTP 响应标头: |
3689 | 3688 | |
3690 | 3689 | abort(403, 'Unauthorized.', $headers); | … | … |
3738 | 3737 | |
3739 | 3738 | return back(); |
3740 | 3739 | |
3741 | ||
3742 | ||
3740 | ||
3741 | ||
3743 | 3742 | <a name="method-bcrypt"></a> |
3744 | 3743 | #### `bcrypt()` {.collection-method} |
3745 | 3744 | … | … |
3805 | 3804 | |
3806 | 3805 | $collection = collect(['taylor', 'abigail']); |
3807 | 3806 | |
3808 | ||
3809 | ||
3807 | ||
3808 | ||
3810 | 3809 | <a name="method-config"></a> |
3811 | 3810 | #### `config()` {.collection-method} |
3812 | 3811 | … | … |
3858 | 3857 | dd($value1, $value2, $value3, ...); |
3859 | 3858 | |
3860 | 3859 | 如果你不想停止脚本的执行,请改用 [`dump`](#method-dump) 函数。 |
3861 | ||
3862 | ||
3860 | ||
3861 | ||
3863 | 3862 | <a name="method-dispatch"></a> |
3864 | 3863 | #### `dispatch()` {.collection-method} |
3865 | 3864 | … | … |
3921 | 3920 | @endfor |
3922 | 3921 | ``` |
3923 | 3922 | |
3924 | ||
3925 | ||
3923 | ||
3924 | ||
3926 | 3925 | 默认情况下,`fake` 函数将使用 `config/app.php` 配置文件中的 `app.faker_locale` 配置选项; 但是,你也可以通过将语言环境传递给 `fake` 函数来指定语言环境。 每个语言环境将解析一个单独的单例: |
3927 | 3926 | |
3928 | 3927 | fake('nl_NL')->name() | … | … |
3983 | 3982 | </form> |
3984 | 3983 | |
3985 | 3984 | <a name="method-now"></a> |
3986 | ||
3987 | ||
3985 | ||
3986 | ||
3988 | 3987 | #### `now()` {.collection-method} |
3989 | 3988 | |
3990 | 3989 | `now` 函数为当前时间创建一个新的 `Illuminate\Support\Carbon` 实例: | … | … |
4033 | 4032 | <a name="method-redirect"></a> |
4034 | 4033 | #### `redirect()` {.collection-method} |
4035 | 4034 | |
4036 | ||
4037 | ||
4035 | ||
4036 | ||
4038 | 4037 | `redirect` 函数返回一个[重定向 HTTP 响应](/docs/laravel/10.x/responses#redirects),或者如果不带参数调用则返回重定向器实例: |
4039 | 4038 | |
4040 | 4039 | return redirect($to = null, $status = 302, $headers = [], $https = null); | … | … |
4090 | 4089 | return $this->method(); |
4091 | 4090 | }); |
4092 | 4091 | |
4093 | ||
4094 | ||
4092 | ||
4093 | ||
4095 | 4094 | 你还可以将第二个参数传递给「rescue」函数。 如果在执行闭包时发生异常,这个参数将是应该返回的「默认」值: |
4096 | 4095 | |
4097 | 4096 | return rescue(function () { | … | … |
4145 | 4144 | // Sleep for 100ms on first retry, 200ms on second retry... |
4146 | 4145 | }); |
4147 | 4146 | |
4148 | ||
4149 | ||
4147 | ||
4148 | ||
4150 | 4149 | 要仅在特定条件下重试,您可以将闭包作为第四个参数传递给 `retry` 函数: |
4151 | 4150 | |
4152 | 4151 | use Exception; | … | … |
4198 | 4197 | // ... |
4199 | 4198 | }); |
4200 | 4199 | |
4201 | ||
4202 | ||
4200 | ||
4201 | ||
4203 | 4202 | <a name="method-throw-if"></a> |
4204 | 4203 | #### `throw_if()` {.collection-method} |
4205 | 4204 | … | … |
4266 | 4265 | |
4267 | 4266 | $validator = validator($data, $rules, $messages); |
4268 | 4267 | |
4269 | ||
4270 | ||
4268 | ||
4269 | ||
4271 | 4270 | <a name="method-value"></a> |
4272 | 4271 | #### `value()` {.collection-method} |
4273 | 4272 | … | … |
4340 | 4339 | ]); |
4341 | 4340 | |
4342 | 4341 | 默认情况下,给定的回调将执行一次(一次迭代),并且它们的持续时间将显示在浏览器/控制台中。 |
4343 | ||
4344 | ||
4342 | ||
4343 | ||
4345 | 4344 | 要多次调用回调,你可以将回调应调用的迭代次数指定为方法的第二个参数。 当多次执行回调时,「基准」类将返回在所有迭代中执行回调所花费的平均毫秒数: |
4346 | 4345 | |
4347 | 4346 | Benchmark::dd(fn () => User::count(), iterations: 10); // 0.5 ms | … | … |
4388 | 4387 | ->then(fn (User $user) => $user); |
4389 | 4388 | ``` |
4390 | 4389 | |
4391 | ||
4392 | ||
4390 | ||
4391 | ||
4393 | 4392 | <a name="lottery"></a> |
4394 | 4393 | ### Lottery |
4395 | 4394 | … | … |
4429 | 4428 | |
4430 | 4429 | // Lottery will return to normal behavior... |
4431 | 4430 | Lottery::determineResultsNormally(); |
4431 | ||
4432 | 4432 | |
4433 |