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;

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

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.