The Laravel team released v11.13 mid-week last week and v11.14 this week. These releases add new string methods like chopStart and chopEnd, Commonmark extension support with Laravel’s String markdown method, a Number::pairs() method, and more.
String chopStart and chopEnd (v11.13)
Tim MacDonald contributed two string methods for chopping characters off the beginning or end of a string. The chopStart and chopEnd methods are available using the Str o Stringable` class:
Str::chopEnd(‘path/to/file.php’, ‘.php’);
// “path/to/file”
Str::chopStart(‘https://laravel.com’, [‘https://’, ‘http://’]);
// laravel.com
Add Support for Extensions to Str::markdown() and the Stringable Class
Tony Lea contributed support for passing Commonmark extensions as a third parameter to the the Str::markdown() method:
$html = Str::markdown($markdown_contents, [], [
new AttributesExtension(),
new TaskListExtension(),
]);
In Laravel 11.14, Luke Downing followed up Tony Lea’s contribution by adding support for Commonmark extensions to the Stringable class:
$html = str(‘# My Heading’)->markdown(
extensions: [new HeadingPermalinksExtension()]
);
Macroable TokenGuard (v11.13)
@Iman added the Macroable trait in the TokenGuard class to support custom macros on this guard. See Pull Request #51922 for details.
Add Number::pairs() (v11.13)
Adam Campbell contributed the Number::pairs() method that ” provides the ability to ‘split’ a number into pairs of min/max values. It’s sort of like sliding, except the method will determine the values for you.”:
$output = Number::pairs(25, 10);
// [[1, 10], [11, 20], [21, 25]]
$output = Number::pairs(25, 10, 0);
// [[0, 10], [10, 20], [20, 25]]
$output = Number::pairs(10, 2.5, 0)
// [[0, 2.5], [2.5, 5.0], [5.0, 7.5], [7.5, 10.0]]
Mark Sensitive Parameters with PHP’s SensitiveParameter Attribute (v11.14)
Philip Iezzi contributed updates to Laravel to attempt to mark sensitive parameters with PHP >= 8.2’s SensitiveParameter attribute. This is an excellent reminder to leverage this attribute in application code if you run PHP >= 8.2.
See Pull Request #51940 for details.
Improvements to the artisan serve Command
Seth Phat contributed improvements to the artisan serve command:
Print out a better request time, for requests that take less than 1 second, ~0s doesn’t seem so helpful at all.
Show the request’s route instead of “………”
Requests that take less than 1 second now print the time in milliseconds instead of 0s:
Release notes
Laravel 11.13 was released mid-week last week so the following release notes are from both versions. You can see the complete list of new features and updates below and the diff between 11.12.0 and 11.14.0 on GitHub. The following release notes are directly from the changelog:
v11.14.0
Adding Pest stubs to publish command by @bartdenhoed in https://github.com/laravel/framework/pull/51933
[11.x] Added attempts() method to FakeJob by @JamesFreeman in https://github.com/laravel/framework/pull/51951
[11.x] Run all Workflows on Ubuntu 24.04 by @Jubeki in https://github.com/laravel/framework/pull/51946
[11.x] Improve PHPDoc for mapSpread Method in Arr Class & Remove Warning from IDE by @lmottasin in https://github.com/laravel/framework/pull/51952
Bump braces from 3.0.2 to 3.0.3 in /src/Illuminate/Foundation/resources/exceptions/renderer by @dependabot in https://github.com/laravel/framework/pull/51955
[11.x] Remove unreachable code in AssertableJsonString by @seriquynh in https://github.com/laravel/framework/pull/51943
[11.x] Fix TestResponseAssert docblock by @seriquynh in https://github.com/laravel/framework/pull/51942
[11.x] feat: add more specific types and tests for helpers by @calebdw in https://github.com/laravel/framework/pull/51938
[11.x] Mark sensitive params with SensitiveParameter attribute by @onlime in https://github.com/laravel/framework/pull/51940
[11.x] Adds support for Markdown extensions to the Stringable class. by @lukeraymonddowning in https://github.com/laravel/framework/pull/51932
[11.x] Add secret method declaration to ComponentsFactory class by @seriquynh in https://github.com/laravel/framework/pull/51949
[11.x] Run Workflows on Windows 2022 and with bash instead of powershell by @Jubeki in https://github.com/laravel/framework/pull/51958
[11.x] Fix duplicated return type PHPDoc by @chu121su12 in https://github.com/laravel/framework/pull/51965
[11.x] Fix test failure message by @nshiro in https://github.com/laravel/framework/pull/51974
[11.x] Update tests to ensure mail Message implements the fluent interface pattern by @seriquynh in https://github.com/laravel/framework/pull/51969
[11.x] Set previous exception on HttpResponseException by @hafezdivandari in https://github.com/laravel/framework/pull/51968
[11.x] Fix typo in SupportCollectionTest by @zbundy in https://github.com/laravel/framework/pull/51966
[11.x] Improvements for the ServeCommand (add more loves & elevate DX) by @sethsandaru in https://github.com/laravel/framework/pull/51957
[11.x] Adds support for using castAsJson with a MariaDb connection by @haniha in https://github.com/laravel/framework/pull/51963
[11.x] Add support for acting on attributes through container by @innocenzi in https://github.com/laravel/framework/pull/51934
[11.x] Fix Component::resolveComponentsUsing test by @seriquynh in https://github.com/laravel/framework/pull/51988
[11.x] Update composer.json files to provide PSR implementations by @seriquynh in https://github.com/laravel/framework/pull/51983
[11.x] add queued closure type for soft delete events by @hpiaia in https://github.com/laravel/framework/pull/51982
[11.x] Fix using container nesting to make the same ‘abstract’ in different context by @guiqibusixin in https://github.com/laravel/framework/pull/51989
[11.x] Fix sync is running touch query twice by @Tofandel in https://github.com/laravel/framework/pull/51984
v11.13.0
[11.x] Add Support for Extensions in Str::markdown Method by @tnylea in https://github.com/laravel/framework/pull/51907
[11.x] Update config:show command by @seriquynh in https://github.com/laravel/framework/pull/51902
[11.x] Fix console prompt docblock by @seriquynh in https://github.com/laravel/framework/pull/51913
[11.x] Fix prohibit docblock by @seriquynh in https://github.com/laravel/framework/pull/51916
[11.x] Mark $queue as nullable by @timacdonald in https://github.com/laravel/framework/pull/51912
use Macroable trait on TokenGuard by @imanghafoori1 in https://github.com/laravel/framework/pull/51922
[11.x] Update Command::fail() dockblock and tests by @seriquynh in https://github.com/laravel/framework/pull/51914
Revert and add test by @jasonmccreary in https://github.com/laravel/framework/pull/51924
[11.x] Display view creation messages by @nshiro in https://github.com/laravel/framework/pull/51925
[11.x] Introduce Str::chopStart and Str::chopEnd by @timacdonald in https://github.com/laravel/framework/pull/51910
feat: Add Number::pairs by @hotmeteor in https://github.com/laravel/framework/pull/51904
[11.x] Fixes escaping path via Process given commands as array by @crynobone in https://github.com/laravel/framework/pull/51926
[11.x] Make MultipleInstanceManager driver field customizable by @princejohnsantillan in https://github.com/laravel/framework/pull/51905
[11.x] Account for long strings on new Laravel error page by @shengslogar in https://github.com/laravel/framework/pull/51880
The post New String Helpers and ServeCommand Improvements in Laravel 11.14 appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Source: Read More