How to get random string in Laravel

Updated at 08-Mar-2022, By samar

How to get random string in Laravel

Through many examples, we will learn how to resolve the "How to get random string in Laravel".

Sometimes we need to get random string to generate unique URL and to generate the unique username while creating user record or any random string which we want to generate like password.
  • Generate random string in Laravel

    use Illuminate\Support\Str;
    
    $randomStr = Str::random(4);
    

    Import Str and call random method using Str with a specific number of length.

Back to code snippet queries related laravel