Top Questions Ask a Question Answer a Question Blogs Write a Blog
How to make Helper own custom helper function in laravel ?
1 answer, 0 shares, 374 views

10 months ago

laravel helper function

  1. Make file helpers.php in app directory (or anywhere)
  2. Add files line in composer.json

"autoload": {

"files": [



"classmap": [




"psr-4": {

          "App\\": "app/"



Once you add a new path to the files array, you need to dump the autoloader:

composer dump-autoload

Now write function to the helpers.php, (here is simple custom function example which return user avatar if user is logged in else return the default image)


function user_avatar(){


        return auth()->user()->avatar;


        return url('/img/user.png');




and you can access this function by calling 

<?php  user_avatar() ?>