Laravel 7.19 Released
Published on by Paul Redmond
The Laravel team released v7.19.0 with new scheduler frequency shortcuts, conditionally appending attributes to API resources and a new Stringable when() method:
Scheduler Frequency Shortcuts
Sjors Ottjes contributed more useful scheduler frequency shortcuts:
-
everyTwoHours()
-
everyThreeHours()
-
everyFourHours()
-
everySixHours()
They provide readable shortcuts instead of using cron
:
// Using cron$schedule->job(SyncSomething::class)->cron('0 */2 * * *'); // Shortcut from this release$schedule->job(SyncSomething::class)->everyTwoHours();
Conditionally Return Appended Attributes in API Resources
Jess Archer contributed a whenAppended
method for API resources to append attributes conditionally. Here are some examples taken from the contributed tests:
public function toArray($request){ return [ 'id' => $this->id, 'first' => $this->whenAppended('is_published'), 'second' => $this->whenAppended('is_published', 'override value'), 'third' => $this->whenAppended('is_published', function () { return 'override value'; }), 'fourth' => $this->whenAppended('is_published', $this->is_published, 'default'), 'fifth' => $this->whenAppended('is_published', $this->is_published, function () { return 'default'; }), ];} // Controller Examplereturn new UserResource($user->append('is_subscribed'));
Scheduled Task Failed Event
Freek Van der Herten contributed a ScheduledTaskFailed
event that fires when a scheduled task fails:
$this->dispatcher->dispatch(new ScheduledTaskFailed($event, $e));
Stringable when() Method
Manojkiran Appathurai contributed a Stringable::when()
method to conditionally run some “stringable” code when true
:
Str::of($blogContent) ->when(! Auth::check(), function ($stringable) { return $stringable ->limit(20) ->append('To Continue reading ') ->append(new HtmlString( '<a href="#">Get a Subscription</a>' )); });
Release Notes
You can see the full list of new features and updates below and the diff between 7.18.0 and 7.19.0 on GitHub. The following release notes are directly from the changelog:
v7.19.0
Added
- Added
everyTwoHours()
|everyThreeHours()
|everyFourHours()
|everySixHours()
methods toIlluminate\Console\Scheduling\ManagesFrequencies
(#33393) - Conditionally returning appended attributes in API resources (#33422)
- Added
ScheduledTaskFailed
event (#33427) - Added
Illuminate\Support\Stringable::when()
(#33455)
Fixed
- Fixed signed urls with custom parameters (bcb133e)
- Determine model key name correctly in Illuminate/Validation/Concerns/ValidatesAttributes.php (a1fdd53)
- Fixed notifications database channel for anonymous notifiables (#33409)