The Str::finish function adds a single instance of the given value to a string if it does not already end with that value.



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\

May this example help you