How to Get a String after the Last Occurrence of a String or Character in Laravel
In this lesson, we are going to see how to get a string after the last occurrence of a string or character in Laravel, the afterLast helper method is used to return a section of a string that appears after the last occurrence of the provided string.
The Str::afterLast helper method
The afterLast() method is used to return a section of a string after the last occurrence of a specific string.
use Illuminate\Support\Str;
$website = 'http://www.website.com/tech/posts';
$part = Str::afterLast($website, '/');
echo $part;
// Returns "posts"