Creating Helpers in a Laravel App through controller — StudySection Blog

Study Section
2 min readMar 25, 2021

--

Creating Helpers in a Laravel App through controller — StudySection Blog
Creating Helpers in a Laravel App through controller — StudySection Blog

Helpers are built-in functions that we can call from anywhere in the laravel project. Helpers are global f unctions that can be called in controller method and as well as in views without importing class of a method. We can create our own helper classes. You can create helpers anywhere in the app folder depending on your choice.

Here are my two chosen directory locations.

  1. app/helpers.php
  2. app/Http/helpers.php

Step 1: Create a helper file
Go to/app/Helpers and create file helper.php

Step 2: Write the helper function

Step 3: Include helper file in our composer.json

To load our file having helper functions we need to add it in the files array of the autoload object inside the composer.json file as shown below. It will load the file on bootstrapping of the application.

After adding your file in the composer.json file run the following:
composer dump-autoload

Now on every request, the helper.php file will be loaded automatically because Laravel requires Composer’s autoloader in public/index.php.

Use of helper method in the controller

Being the most extensively used JavaScript library, a jQuery certification will add enormous value to your skill-set. jQuery provides various functionalities to the developer in order to develop complex applications with ease and efficiency.

Originally published at https://studysection.com on March 25, 2021.

--

--

Study Section
Study Section

Written by Study Section

The most loved online platform for eCertification in several subjects including but not limited to Software Development, Aptitude and more.

No responses yet