Online Forum To Support Coders With Technical Assistance - Read Write Execute

Create custom helper in laravel 5

Ankit Agrawal
Ankit Agrawal
Published on June 27, 2018 · 1 min read

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();
Was this article helpful?
Ankit Agrawal

Ankit Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article Stripe payment gateway integration in php Next Article → Fetch facebook profile data using javascript