Never Miss a Laravel Release 🚀
The Laravel team released version 12.40.0 this week with new time helper functions, the ability to schedule tasks to run on specific days, pausing and resuming queues, and more.
Time Helpers
Taylor Otwell added time helper functions to the Illuminate\Support namespace and new methods on the support Carbon class:
use Illuminate\Support\Carbon; // Plus and minus methods support years, months, weeks,// days, hours, minutes, seconds, microseconds.Carbon::now()->plus(years: 1, days: 5); Carbon::now()->minus(weeks: 4);
The support namespace has the following helpers, which return a CarbonInterval instance:
use function Illuminate\Support\{seconds, minutes, hours, days, years}; seconds(5);minutes(5);hours(1);days(30);years(1); /*Carbon\CarbonInterval {#1277 interval: + 1y,}*/
Here are a few examples of how you might use the support Carbon methods and helper functions:
use function Illuminate\Support\minutes; Cache::put('name', 'Taylor', minutes(5)); Invitation::create([ 'expires_at' => now()->plus(weeks: 1),]);
Schedule Tasks on Specific Days
Yousef Kadah contributed a daysOfMonth() method to run tasks on multiple, specific days of the month:
// Variadic syntax$schedule->command('generate-reports') ->daysOfMonth(1, 10, 20); // Array syntax$schedule->command('generate-reports') ->daysOfMonth([1, 10, 20]);
Encoding Validation Rule
Jamie York contributed an encoding validation rule that checks the contents of a file and ensures it matches a specific encoding:
use Illuminate\Support\Facades\Validator;use Illuminate\Validation\Rules\File; Validator::validate($input, [ 'attachment' => [ 'required', File::types(['csv'])->encoding('utf-8'), ],]);
Pause/Resume a Queue
Yousef Kadah contributed the ability to pause and resume queues using a command. The queue argument is the connection and queue name. For example, the following is the database connection and default is the queue name:
php artisan queue:pause database:default php artisan queue:continue database:default
See the documentation for details on pausing and resuming queue workers.
Release notes
You can see the complete list of new features and updates below and the diff between 12.39.0 and 12.40.0 on GitHub. The following release notes are directly from the changelog:
v12.40.0
- [12.x] Improve return type of
Str::replace()by @axlon in https://github.com/laravel/framework/pull/57820 - [12.x] Fixup PHP 8.5 deprecations in
SupportArrTestby @jnoordsij in https://github.com/laravel/framework/pull/57822 - Add daysOfMonth() method to schedule tasks on specific days by @yousefkadah in https://github.com/laravel/framework/pull/57817
- [12.x] Add
encodingvalidation rule for uploaded files by @ziadoz in https://github.com/laravel/framework/pull/57823 - [12.x] Allow CachedState properties to be nullable by @jackbayliss in https://github.com/laravel/framework/pull/57826
- [12.x] Resolve failing encoding test by @jackbayliss in https://github.com/laravel/framework/pull/57827
- [12.x] Fixing MemoizedStore with Redis Cluster by @vadimonus in https://github.com/laravel/framework/pull/57828
- [12.x] Update encoding validation message by @jackbayliss in https://github.com/laravel/framework/pull/57834
- [12.x] Use
scopedIfinCacheManager::memo()by @angelej in https://github.com/laravel/framework/pull/57833 - [12.x] Fixing RedisTaggedCache::flushStale with PhpRedisClusterConnection by @vadimonus in https://github.com/laravel/framework/pull/57837
- [12.x] Add default parameter support to
Request::fluent()method by @michaelnabil230 in https://github.com/laravel/framework/pull/57840 - [12.x] Fix embedded image Content-ID inconsistency in cloned emails by @yinheli in https://github.com/laravel/framework/pull/57726
- [12.x] PredisClusterConnection::keys() by @vadimonus in https://github.com/laravel/framework/pull/57841
- [12.x] PHP 8.5 Compatibility by @crynobone in https://github.com/laravel/framework/pull/57835
- [12.x] RateLimiter remaining to 0 to prevent negative values. by @Button99 in https://github.com/laravel/framework/pull/57851
- [12.x] Update RequestException@report() to return false by @cosmastech in https://github.com/laravel/framework/pull/57847
- Time by @taylorotwell in https://github.com/laravel/framework/pull/57856
- Feature/queue pause resume by @yousefkadah in https://github.com/laravel/framework/pull/57800
- [12.x] Fixing RedisTaggedCache::flushValues with PredisClusterConnection by @vadimonus in https://github.com/laravel/framework/pull/57848
- [12.x] Improve typehints for
QueriesRelationshipsby @CasEbb in https://github.com/laravel/framework/pull/57830 - [12.x] Fix flaky test by @cosmastech in https://github.com/laravel/framework/pull/57864
- [12.x] optimize
AbstractRouteCollection@toSymfonyRouteCollection()by @cosmastech in https://github.com/laravel/framework/pull/57870 - [12.x] optimize
AbstractRouteCollection@matchAgainstRoute()by @cosmastech in https://github.com/laravel/framework/pull/57871 - [12.x] Moving redis integration tests by @vadimonus in https://github.com/laravel/framework/pull/57860
- [12.x] Incorrect result of MemoizedStore::many with numeric keys and empty prefix by @vadimonus in https://github.com/laravel/framework/pull/57862
- [12.x] Add testWrapEdgeCases for Str::wrap edge cases by @miladev95 in https://github.com/laravel/framework/pull/57861
- [12.x] Add parameter validation to Collection::sliding() method. by @Button99 in https://github.com/laravel/framework/pull/57875
- [12.x] Update
pathmethod return type to always be a non-null string by @IsmailBourbie in https://github.com/laravel/framework/pull/57873 - Added Google's antigravity IDE support in ResolvesDumpSource.php by @yeasherarafath in https://github.com/laravel/framework/pull/57885
- [12.x] Clean up queue pausing by @cosmastech in https://github.com/laravel/framework/pull/57863
- [12.x] Simplify
ParsesQueue@parseQueuelogic by @rodrigopedra in https://github.com/laravel/framework/pull/57886 - [12.x] Improve lazy loading violation callable typehints by @cosmastech in https://github.com/laravel/framework/pull/57896
- [12.x] Fix Accept header cache invalidation when header is modified by @faisuc in https://github.com/laravel/framework/pull/57874
- [12.x] Fix flaky test in CacheArrayStore (increment) by @sumaiazaman in https://github.com/laravel/framework/pull/57905
- [12.x] Fix flaky test in ArraySessionHandler (garbage collection) by @sumaiazaman in https://github.com/laravel/framework/pull/57904
- [12.x] Fix flaky test in ArraySessionHandler (almost expired session) by @sumaiazaman in https://github.com/laravel/framework/pull/57903
- [12.x] Fix flaky test in ArraySessionHandler (expired session) by @sumaiazaman in https://github.com/laravel/framework/pull/57902