
Laravel recursive function in controller
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
Answers 1
-
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; }
0
Random Code Snippet Queries: Laravel
- Route prefix with auth middleware in laravel
- Get ids in array from users table
- Split an Eloquent Collection by half in Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- Get last year created records in Laravel
- How to pass data to multiple partial view files in laravel
- How to print form data in laravel
- How to create projects method with belongstomany relationship in user model
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- How to get last year records count with month wise in Laravel
- Add a subselect based on relationship using withAggregate method
- Array to string conversion laravel Controller
- Laravel insert query not working
- Permission denied error while creating storage link in Laravel
- Ajax GET request in laravel
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- How to get path from current URL in Laravel
- Delete records with relationship in laravel
- How to get selected categories on edit record with Select2
- Redirect from www to non www in laravel using htaccess
- How to create pivot table in laravel using migration
- How to get IP address in laravel
- Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused)"
- How to add dynamic page title in Laravel view
- Get the post details if it has at least one comment in comments table