Create Custom helper and use their function in laravel 7

helper

Helper is a very useful file and most using to globally function defined and it’s used every place you want to like in your project.

Laravel includes a variety of global “helper” PHP functions. Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient.

So, let start our tutorial

Step 1: Changes in composer.json

Open your composer.json file and put the below code.

"autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "files": [
            "app/Http/helpers.php"
        ]
    },

Now open your terminal and put below code:

composer dump-autoload

Step 2: Create a helper file

In this step, we have to create an app/helpers.php

<?php
function notificationMsg($text, $message){
	\Session::flash($text, $message);
}

I hope your function in ready in Laravel 7.

About Dhaval Shah

My name is Dhaval Shah. I'm a PHP developer, entrepreneur and CEO of DAG inventions PVT ltd. I live in India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Java-script, JQuery, Laravel, WordPress and Bootstrap.
Follow me on Github / Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!