Skip to content

Instantly share code, notes, and snippets.

View lvcasjm's full-sized avatar
🙂

Lucas Martin lvcasjm

🙂
View GitHub Profile
@ryzr
ryzr / YourServiceProvider.php
Last active July 23, 2018 04:19
Laravel Str Macros
<?php
Str::macro('sentences', function($value, $sentences = 2, $end = '...')
{
preg_match('/(.+?(?:(?<![\s.]\p{Lu})[.!?])){1,'.$sentences.'}/u', $value, $matches);
if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) {
return $value;
}