Hi everybody.
Today I am going to discuss on a topic “how to create a custom helper where you can define your common custom function?”.You know laravel is the best framework of php.Most developers are using this framework to develop an application.If you are developing an application with laravel and it’s a big system like CRM or account management then there may be you have called a common function in anywhere of your application.It may be in controller or somewhere of your application.
So, first of all, create a helpers.php in app folder of your application.After that load the helper with composer.Add the following code inside the composer json file.
"autoload": { "classmap": [ "database" ], "files": [ "app/Http/helpers.php" ], "psr-4": { "App\\": "app/" } },
After adding that to your composer.json file, run the following command:
Star the command prompt and goto to project folder and run the command
composer dump-autoload
Finally you can create a function and call it inside the controller.
demo()
Now define the function inside the helpers.php
function demo(){ echo "ok"; }