Laravel recursive function in controller
Created at 06-Oct-2021 ,
By samar
Laravel recursive function in controller
In this session, we’ll try our hand at solving the "Laravel recursive function in controller" puzzle by using the computer language.
Recursive function calls itself directly or indirectly. Here we have a recursive function in controller which call itself until the condition becomes false is called by another method in controller-
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 disable timestamps in laravel
- How to get records in random order in laravel
- Setup laravel project with docker
- Route [password.request] not defined
- Laravel 9 pagination with search filter
- Laravel migration add foreign key to existing table
- Redirect from www to non www in laravel using htaccess
- Use withCount() to Calculate Child Relationship Records
- Calculate age from date of birth in Laravel
- How to return a column with different name in Laravel
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- How to check data inserted or deleted in pivot after toggle method
- How to check records exist in loaded relationship in Laravel blade view
- How to send ID to another page in Laravel
- How to check query string exists or not in laravel blade
- How to fill a column automatically while creating records in Laravel
- Update last created record in Laravel
- How to use more than one query scope in Laravel
- The use statement with non-compound name 'DB' has no effect
- How to display validation error in laravel
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- Laravel create table migration with model
- How to get user information using hootlex/laravel-friendships package in laravel
- How to display pivot table column value in laravel
- Create a record if not exist in laravel