
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 display HTML tags In Laravel blade
- 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
- Undefined property: stdClass::$title
- Generate random string lowercase in Laravel
- Multiple Level eager loading in Laravel
- How to get single column value in laravel
- The openssl extension is required for SSL/TLS protection but is not available
- How to fill a column automatically while creating records in Laravel
- Laravel change date format
- Create model with migration and seeder
- Comment .env file in laravel
- Recursive function example code PHP Laravel
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- Create record with unique slug in laravel
- How to avoid duplicate entries in pivot table in Laravel
- How to get date from created_at field in laravel
- Laravel specific table Migration
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Link storage folder in laravel 8
- How to get database name in Laravel 9 ?
- Target class [HomeController] does not exist
- Call to a member function pluck() on array
- Include External CSS and JS file in Laravel
- If condition in foreach loop in laravel
- Run artisan command to generate key in laravel