Laravel 10.15: Sub-minute Task Scheduling, Raw SQL Query Builder Methods, và nhiều tính năng khác
Tuần này, nhóm Laravel đã phát hành phiên bản 10.15 với sub-minute scheduling, raw SQL query build methods, việc ném ngoại lệ HTTP từ một view và nhiều tính năng khác:
Sub-minute scheduling
Jess Archer đã đóng góp vào tính năng Lập lịch trong vòng ít phút, cung cấp các tùy chọn tần suất mới khi scheduling jobs(lập lịch công việc_:
$schedule->job(new ExampleJob)->everySecond();
$schedule->job(new ExampleJob)->everyTwoSeconds();
$schedule->job(new ExampleJob)->everyFiveSeconds();
$schedule->job(new ExampleJob)->everyTenSeconds();
$schedule->job(new ExampleJob)->everyFifteenSeconds();
$schedule->job(new ExampleJob)->everyTwentySeconds();
$schedule->job(new ExampleJob)->everyThirtySeconds();
Trước đây, tần suất cao nhất mà Laravel cung cấp là mỗi phút mà không cần sử dụng một gói cộng đồng nào. Đây là một bổ sung tuyệt vời đối với những người cần chạy các nhiệm vụ lập lịch với tần suất cao hơn. Vui lòng xem Pull Request #47279 để biết thông tin chi tiết, lưu ý và thảo luận về tính năng này!
Raw SQL methods added to query builders
Chúng tôi đã đề cập rằng Đầu ra Truy vấn Thô Kèm Ràng buộc sẽ được tích hợp vào Laravel 10 và đã được phát hành trong phiên bản 10.15! Tobias Petry đã đóng góp tính năng này, bao gồm ba phương thức mà bạn có thể sử dụng để xem truy vấn SQL thô kèm ràng buộc của trình xây dựng truy vấn (query builder):
$query->ddRawSql(); // SQL string output via dd()
$query->dumpRawSql(); // SQL string output via dump()
$query->toRawSql(); // raw sql string
Nuno Maduro đã đóng góp hỗ trợ đính kèm nội dung trực tiếp trong các thông báo mailables của Markdown. Vui lòng xem Pull Request #47643 và Pull Request #47603 để biết thêm chi tiết.
Inline attachment support for “notification” markdown mailable
DB::getRawQueryLog() method
@Fuwasegu đã đóng góp phương thức getRawQueryLog() hoạt động tương tự như DB::getQueryLog():
DB::enableQueryLog();
// ... perform queries
$logs = DB::getRawQueryLog();
/*
[
[
"raw_query" => "select * from "users" where "id" in (3, 6, 8)"
"time" => 4.06
]
]
*/
String isUrl() method
Graham Campbell đã đóng góp phương thức isUrl() để xác thực xem một chuỗi có phải là một URL hợp lệ hay không. Phương thức này sử dụng logic từ phương thức validateUrl() của validator, và hiện tại phương thức validateUrl() gọi phương thức mới này:
Allow HTTP exceptions to be thrown in views
Nuno Maduro đã đóng góp khả năng ném ngoại lệ HTTP từ các view:
@php
if (! Gate::check('view-books')) {
abort(403);
}
$books = auth()->user()->books;
@endphp
@foreach ($books as $book)
<div>
{{ $book->title }}
</div>
@endforeach
Ghi chú phát hành
Bạn có thể xem danh sách đầy đủ các tính năng mới và cập nhật dưới đây, cũng như sự khác biệt giữa phiên bản 10.14.0 và 10.15.0 trên GitHub. Các ghi chú phát hành sau đây được lấy trực tiếp từ nhật ký thay đổi (changelog):
v10.15.0
- [10.x] Change return type of
getPrivateToken
in AblyBroadcaster by @milwad-dev in https://github.com/laravel/framework/pull/47602 - [10.x] Add toRawSql, dumpRawSql() and ddRawSql() to Query Builders by @tpetry in https://github.com/laravel/framework/pull/47507
- [10.x] Fix recorderHandler not recording changes made by middleware by @j3j5 in https://github.com/laravel/framework/pull/47614
- Pass queue from Mailable to SendQueuedMailable job by @Tarpsvo in https://github.com/laravel/framework/pull/47612
- [10.x] Sub-minute Scheduling by @jessarcher in https://github.com/laravel/framework/pull/47279
- [10.x] Fixes failing tests running on DynamoDB Local 2.0.0 by @crynobone in https://github.com/laravel/framework/pull/47653
- [10.x] Allow password reset callback to modify the result by @GrahamCampbell in https://github.com/laravel/framework/pull/47641
- Forget with collections by @joelbutcher in https://github.com/laravel/framework/pull/47637
- [10.x] Do not apply global scopes when incrementing/decrementing an existing model by @cosmastech in https://github.com/laravel/framework/pull/47629
- [10.x] Adds inline attachments support for “notifications” markdown mailables by @nunomaduro in https://github.com/laravel/framework/pull/47643
- Assertions for counting outgoing mailables by @jasonmccreary in https://github.com/laravel/framework/pull/47655
- [10.x] Add getRawQueryLog() method by @fuwasegu in https://github.com/laravel/framework/pull/47623
- [10.x] Fix Storage::cloud() return type by @tattali in https://github.com/laravel/framework/pull/47664
- [10.x] Add
isUrl
to theStr
class and use it from the validator by @GrahamCampbell in https://github.com/laravel/framework/pull/47688 - [10.x] Remove unwanted call to include stack traces by @HazzazBinFaiz in https://github.com/laravel/framework/pull/47687
- [10.x] Make Vite throw a new
ManifestNotFoundException
by @innocenzi in https://github.com/laravel/framework/pull/47681 - [10.x] Move class from file logic in Console Kernel to dedicated method by @CalebDW in https://github.com/laravel/framework/pull/47665
- [10.x] Dispatch model pruning started and ended events by @ziadoz in https://github.com/laravel/framework/pull/47669
- [10.x] Update DatabaseRule to handle Enums for simple where clause by @CalebDW in https://github.com/laravel/framework/pull/47679
- [10.x] Add data_forget helper by @PhiloNL in https://github.com/laravel/framework/pull/47618
- [10.x] Added tests for
isUrl
to Str. by @michaelnabil230 in https://github.com/laravel/framework/pull/47690 - [10.x] Added
isUrl
to Stringable. by @michaelnabil230 in https://github.com/laravel/framework/pull/47689 - [10.x] Tweak return type for missing config by @sfreytag in https://github.com/laravel/framework/pull/47702
- [10.x] Fix parallel testing without any database connection by @deleugpn in https://github.com/laravel/framework/pull/47705
- [10.x] Test Improvements by @crynobone in https://github.com/laravel/framework/pull/47709
- [10.x] Allows HTTP exceptions to be thrown for views by @nunomaduro in https://github.com/laravel/framework/pull/47714