Skip to content

All topics  /  Laravel

Laravel str padRight() function Example

Laravel ·

Hi Guys,

In this blog,I will you how to use laravel str padRight() function example. We will show example of padRight function in laravel.The Str::padRight method wraps PHP's str_pad function, padding the right side of a string with another string until the final string reaches a desired length

Here, I will give you full example for simply str padRight() 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()
    {
        $converted1 = str::padRight('James', 10, '-');
        \Log::info($converted1);
        // output - 'James-----'
        $converted2 = Str::padRight('James', 10);
        \Log::info($converted2);
        // output - 'James     '
    }
}

Output

'James-----'
'James     '

It Will help you...