In this tutorial you will learn about the Laravel Str::random() function Example and its application with practical example.
In this article, I’ll show you how to use laravel Str::random function with example. We will show example of laravel Str::random function in laravel. In this tutorial, we will learn to generate a random string of the specify length in laravel.
Laravel Str::random method
The Str::random method generates a random string of the specified length. This function is mainly used to generate random string.
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Str; class HomeController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { $random1 = Str::random(8); $random2 = Str::random(6); $random3 = Str::random(40); echo 'Random String 1 : '.$random1; echo '<br>'; echo 'Random String 2 : '.$random2; echo '<br>'; echo 'Random String 3 : '.$random3; echo '<br>'; } } |