Laravel has a number of string helpers that make using them simple, including str_limit, str_plural, str_finish, and str_singular. Use Laravel's str_random() utility if you want to create a unique random string. It is really easy to use and very straightforward.
You can easily generate random strings in laravel 6, laravel 7, laravel 8, laravel 9, and laravel 10 versions using the str helper.
str_random() helper take one numeric argument and return number of unique string that you pass as argument. you can see it's syntax and example:
Syntax:
Str::random(number);
OR
str_random(number);
Example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class RandomController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function index()
{
$randomString = Str::random(30);
dd($randomString);
}
}
0 Comments