Laravel, PHP

How to create a globally accessible helper class in Laravel 5.5

Helper class in laravel is a class that contains all those functions which are performs common tasks and can be reused in our application. Here we will create a class which contains reusable functions and these functions can be called every where in your laravel application. So let’s start to create our helper class that will globally accessible.

How to create helper class in laravel

  1. Create a folder inside app directory where your class file will locate. I create helper
  2. Create a php file. I create Helper.php
  3. Now declare your class and functions inside the Helper.php file

class Helper{

//Return specific data of any column of a table

public static function name($id,$model,$ret){
 foreach ($get as $key => $gets) {
    return $gets->$ret;

// Get all data in array form of a table by passing model name

public static function getAll($model){

        return $get;

public static function getSpecific($model,$col,$condition){

return $get;    

public static function getColumn($model,$col,$condition,$operator,$ret){
foreach ($get as $key => $value) {
    return $value->$ret;

  1. Open your composer.json file and write your file location here

Helper class in laravel

"files": [

  1. Run composer dump-autoload command
composer dump-autoload command
  1. And now finally your class is ready to access into overall laravel application. Trying to access a static function of Helper class named ‘name($id,$model,$ret)’. This function takes 3 parameters

Laravel 5.6 is going to release .check new features.

  • $id – id of the row
  • $model – Name of model where we will search record.
  • $ret – Name of returning column after matching record successfully in the table. like email,name etc.

Explore More

If you interested to learn more about the helpers claas in laravel , you can visit the official website of laravelĀ
You can also read a detailed article

Hope guys it will help you to create a custom globally accessible helper class in laravel. If you like this post please like and share it. And keep visiting our blog for more latest posts.

Thank you

About Viren-Dra Yadav

Tech Enthlasis | Open Source Lover | Project Manager and DevOps Developer@EighteenPixels | Mad for Speed
View all posts by Viren-Dra Yadav →

Leave a Reply

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