Laravel 5 Custom Helper Functions

Laravel 5 Custom Helper Functions

By : Laravellogic Created : March 6, 2018 View : 532

hello friend, Today I will tell you create custom helper functions in laravel web application

Laravel helper function is a very usefull in your laravel applications basically, helpers in Laravel are built-in utility functions that you can call from anywhere within your application like view model controller etc...

You can also define your own supporting helper functions for your lellwish apps and PHP packages, using the composer to automatically import it.

you are ready i create a custom helper functions, please fillowing below step

Step 1: Create helpers.php file

Goto app/Http and create new file helpers.php

Open the helpers.php file and create a common function in it, as follows

function getUserNotification()
	$data  = \DB::table('notifications')
				->orderBy('id', 'DESC')
	return $data;

Step 2: Edit composer.json file

Now add below code in composer.json file

"autoload": {
    "classmap": [
    "psr-4": {
        "App\\": "app/"
    "files": [
        "app/helpers.php" // <---- Add This Line

Step 3: Composer update

After adding that to your composer.json file, run the following command:

composer dump-autoload

I hope you’ve enjoyed the post and it helps you create your own custom helpers in all time Laravel web application development.