
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
- Call to undefined relationship [user] on model [App\Models\Post]
- SQLSTATE[42000]: Syntax error or access violation: 1055
- How to validate form input data in laravel
- Laravel clone model
- Get count of filter data, while return a small set of records
- Insert data with form validation using ajax in laravel
- If no route matched route::fallback in laravel
- Save or update pivot table data with additional column in Laravel
- Include External CSS and JS file in Laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- How to display user profile after login in laravel
- Laravel save object to database
- How to create belongstomany relation using custom name on custom pivot table
- How to use more than one query scope in Laravel
- Laravel create default admin user
- How to restore deleted records in laravel
- Validation errors for multiple forms on same page Laravel
- Credit card validation in laravel
- How to create pivot table in laravel using migration
- Cast Array to an Object in Controller and then pass to view in laravel
- How to add active class to menu item in laravel
- How to create event and listener in laravel ?
- How to use or operator in laravel
- How to show data by ID in laravel?
- Run artisan command to generate key in laravel