CodeIgniter Laravel PHP Example HTML Javascript jQuery MORE Videos New

How to create and use Custom helper function in Laravel


There are so many build in helper function we are using like

return view('employee.index');
$converted = Str::lower('LARAVEL'); // laravel
    Steps:
  1. Create Helpers folder inside app folder, where we keep file which contain helper function
  2. create Helper.php file inside Helpers folder
  3. if (! function_exists('myCustHelperFunc')) {
            function myCustHelperFunc()
            {
            return "helper function is called"
            }
            }
    
  4. go to composer.json and add or update in autoload object
    "autoload": {
    "files": [
    "app/Helpers/Helper.php"
    ],
    "psr-4": {
    "App\\": "app/",
    "Database\\Factories\\": "database/factories/",
    "Database\\Seeders\\": "database/seeders/"
    }
    },
            }
    
  5. composer dump-autoload ==> run this command on terminal
  6. use function name any where like myCustHelperFunc();