Laravel 10.15: Sub-minute Task Scheduling, Raw SQL Query Builder Methods, and More
Published on by Paul Redmond
This week, the Laravel team released v10.15 with sub-minute scheduling, raw SQL query build methods, throwing an HTTP exception from a view, and more:
Sub-minute scheduling
Jess Archer contributed Sub-minute Scheduling, which provides new frequency options when scheduling jobs:
$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();
Previously, the highest frequency offered was every minute without using a community package. This is an awesome addition for those that need to run scheduled tasks at a greater frequency. See Pull Request #47279 for details, caveats, and discussion around this feature!
Raw SQL methods added to query builders
We mentioned that Raw Query Output With Bindings is Coming to Laravel 10, which was released in v10.15! Tobias Petry contributed this feature, which includes three methods you can use to see a query builder's raw SQL with bindings:
$query->ddRawSql(); // SQL string output via dd()$query->dumpRawSql(); // SQL string output via dump()$query->toRawSql(); // raw sql string
Inline attachment support for "notification" markdown mailable
Nuno Maduro contributed support for inline attachments in notification markdown mailables. See Pull Request #47643 and Pull Request #47603 for more details.
DB::getRawQueryLog() method
@Fuwasegu contributed a getRawQueryLog()
method that works similarly to 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 contributed a isUrl()
method to validate whether a string is a valid url. It uses the logic from the validator validateUrl()
method, which now calls the new method:
use Illuminate\Support\Str; Str::isUrl('https://example.com'); // trueStr::isUrl('ms-officeapp://launchapp'); // trueStr::isUrl('invalid://launchapp'); // falseStr::isUrl('//example.com'); // false
Allow HTTP exceptions to be thrown in views
Nuno Maduro contributed the ability to throw HTTP exceptions from views:
@php if (! Gate::check('view-books')) { abort(403); } $books = auth()->user()->books;@endphp @foreach ($books as $book) <div> {{ $book->title }} </div>@endforeach
Release notes
You can see the complete list of new features and updates below and the diff between 10.14.0 and 10.15.0 on GitHub. The following release notes are directly from the 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