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
- Eager loading dynamically in laravel
- Post model with title and body in laravel 8
- Print last executed query in laravel
- Validation for multiple forms on same page in laravel
- Always load the relationship data with eager loading in Laravel
- How to get the random value form a specific column in laravel ?
- After image selected get validation error in laravel
- Laravel route parameter
- Create model with migration and seeder
- How to get single column value in laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- How to run a specific seeder class in laravel
- Pagination in laravel
- Datetime field in Laravel migration
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- Extra Filter Query on Relationships in Laravel
- Post table seeder laravel 10
- Use withCount() to get total number of records with relationship
- Get current month records in laravel 7/8
- Drop foreign key column in Laravel using migration
- SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
- How to add unique records in pivot columns of Laravel pivot table
- Laravel append URI in route
- 419 page expired error in Laravel
- Laravel URL validation not working