Abdoon Nur
Abdoon Nur

Reputation: 307

Where to write common function or logic in laravel 4.2

I want to use a common function or logic in all controllers on laravel4.2, what would be best way to do this? Does Anyone have any idea?

Upvotes: 1

Views: 330

Answers (1)

Vishal Tarkar
Vishal Tarkar

Reputation: 826

You can use Helper for that.

Create helpers.php in app folder.

You can create normal function there which you can use anywhere in laravel.

Example syntax for function :

function YOUR_FUNCTON_NAME(param1,param2) {
    #YOUR_CODE
}

After creating helpers.php file , add it in app/start/global.php file. like below :

require app_path().'/helpers.php';

And you can use anywhere in your controller like this YOUR_FUNCTON_NAME(param1,param2)

Hope this help.

Upvotes: 1

Related Questions