Skip to content

All topics  /  Laravel

Laravel str finish() function Example

Laravel ·

Hi Guys,

In this blog,I will you how to use laravel str finish() function example. We will show example of finish function in laravel.The Str::finish method adds a single instance of the given value to a string if it does not already end with that value.

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

Example


<?php
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()
    {
        $finish1 = Str::finish("Foo\Bar\Baz", "\");

        
        print_r($finish1);
        // output - Foo\Bar\Baz\
        $finish2 = Str::finish("Foo\Bar\Baz", "\");

        
        print_r($finish2);
        // output - Foo\Bar\Baz\
    }
}

Output

Foo\Bar\Baz\
Foo\Bar\Baz\

It Will help you...