Laravel Str::random() function Example
Hi Guys,
In this blog, I will show how to generate a random string of the specify length in laravel. I want to learn you str random method in laravel. we will talk about laravel string random method. This tutorial will give you how to generate random string of the specified length.
The Str::random method generates a random string of the specified length. This function uses PHP's random_bytes function. If you want to generate random string if you specify the length in laravel then you can use bellow example.
Example
<?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>';
}
}
It will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial