
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
- Remove array keys and values if it does not exist in other array in Laravel
- Display success message in laravel
- Get last week data in Laravel
- Database transactions in laravel
- How to display 1 day ago in comments in laravel view
- Submit form without CSRF token in Laravel
- How to create new user without form submission in laravel
- Laravel 9 pagination with search filter
- Conditional where clause in Laravel
- Laravel API response format
- Run artisan command to generate key in laravel
- Permission denied error while creating storage link in Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- How to check records exist in loaded relationship in Laravel blade view
- Insert dummy data in users table Laravel
- How to add unique records in pivot columns of Laravel pivot table
- Convert input array to comma-separated string in laravel controller
- Property [user] does not exist on this collection instance
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- How to get all posts which contains comments in laravel
- Get last year created records in Laravel
- Cast Array to an Object in Controller and then pass to view in laravel
- How to get only time from created_at in laravel
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- How to pass data to route in laravel?