Recursive function example code PHP Laravel
Created at 08-Mar-2022 ,
By samar
Recursive function example code PHP Laravel
Through many examples, we will learn how to resolve the "Recursive function example code PHP Laravel".
The function which is called itself is a recursive function. Here we have an example code of recursive function which is used to create the username which is called itself till it does not get the unique username for a user while registration process.-
Recursive function in Laravel to generate unique username
public function generateUserName($name){ $username = Str::lower(Str::slug($name)); if(User::where('username', '=', $username)->exists()){ $uniqueUserName = $username.'-'.Str::lower(Str::random(4)); $username = $this->generateUserName($uniqueUserName); } return $username; }
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- On delete set foreign id column value null using migration in laravel 8
- Cannot end a section without first starting one
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- How to restore deleted records in laravel
- First and last item of the array using foreach iteration in laravel blade
- How to get user information using hootlex/laravel-friendships package in laravel
- Route prefix with auth middleware in laravel
- Command to create MySQL Docker image and access the MySQL command-line interface (CLI) within a running Docker container
- Conditional where clause in Laravel
- How to pass data to partial view file in laravel
- How to delete record in Laravel with ajax
- Insert values in pivot table dynamically in laravel
- How to add script on specific view file in laravel while extending layout
- How to get all posts which contains comments in laravel
- How to send email in laravel
- Database transactions in laravel
- Display message with session flash using bootstrap alert class in laravel
- Create model with migration and seeder
- Redirect from www to non www in laravel using htaccess
- Laravel order by date not working
- How to create pivot table in laravel using migration
- How to check relationship is loaded or not in Laravel
- Display data in table using foreach in Laravel
- Get last year created records in Laravel
- How to pass query string with pagination in laravel