Back to Blog

New String Helpers and ServeCommand Improvements in Laravel 11.14

Julian Beaujardin
Julian Beaujardin July 2nd, 2024

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

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