Create custom helper in laravel 5

Laravel support inbuilt helper functionality that we can use in our web application. Please follow the following easy steps to create your own custom helper.

  • First create a folder Helpers in your app directory
  • Now create a file CustomHelper.php in this helpers folder
  • Open newly created file and write the following code
namespace App\Helpers;

class CustomHelper
{
    public static function myCustomFunction()
    {
        echo "hello world";
    }
}
  • Open config/app.php and set aliases for you cutsom helper
'aliases' => [
.
.
.
.
.
'CustomHelper' => App\Helpers\CustomHelper::class

  ],
  • Now ou can use your custom helper’s function in your controller like this
 \CustomHelper::myCustomFunction();