Custom Helper Functions in Laravel

By : PHPErrorCode March 6, 2018 441 Views laravel

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...

Now you have a basic part of Laravel helpers and what they are used for. In this section, I’ll go ahead and demonstrate how you can create your own custom helper that can be used globally in your Laravel web application.

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.