Laravel str afterLast() function Example

Feb 23, 2021



Hi Guys,

In this blog,I will you how to use laravel str afterLast() function example. We will show example of afterLast function in laravel.The Str::afterLast method returns everything after the last occurrence of the given value in a string. The entire string will be returned if the value does not exist within the string.

Here, I will give you full example for simply str afterLast() method in laravel as bellow.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Controllers\FileController;

use Illuminate\Support\Str;

class HomeController extends Controller



* Show the application dashboard.


* @return \Illuminate\Contracts\Support\Renderable


public function index()


$slice = Str::afterLast('App\Http\Controllers\Controller', '\\');







It Will help you...

#Laravel 8

#Laravel 7


#Laravel 6