
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
- How to get images from AWS s3 and display in Laravel blade
- Order by multiple columns in Laravel
- How to create laravel project using composer
- JQuery each loop on json response after ajax in laravel
- Call to undefined method App\Models\User::follow()
- Store logged in user details in session and display in view in laravel
- Class 'App\Rules\Hash' not found in Laravel
- Rendering HTML from database table to view in Laravel
- Wheredate in laravel not working
- Ajax GET request in laravel
- Laravel 5.4 save data to database
- Laravel migration add foreign key to existing table
- Retain selected value of select box in Laravel
- How to generate .env file for laravel?
- How to get last year records count with month wise in Laravel
- How to get route method name in Laravel
- How to get path from current URL in Laravel
- FirstOrCreate() Not Inserting Model
- Get last week data in Laravel
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- How to validate form input data in laravel
- Extract only time from datetime in laravel
- Define variable and use in Laravel controller method
- Get current month records in laravel 7/8
- How to create pivot table in laravel using migration