DEV Community

Cover image for Build your First Laravel Helpers
Mina Farag
Mina Farag

Posted on

Build your First Laravel Helpers

What are Helpers?

helpers are all the little tiny magical methods you'll create today. It's a more advanced way of increasing your code efficiency and clearance.
In a WebDev way of declaring stuff: It's group of custom-built methods but not classes.

Let's Set it up.

using any IDE - i use sublime myself. Please create a new (.php) file & name it (helpers.php), Then save it to your app directory.

your-side (dir) will be like



  • we don't use the (.blade.php) layer for this file.

let's assume you wanna inject your layout.blade.php template file with FontAwesome Icons-Api. So the usual way is to just add a link tag referencing your Api like the following:


<link rel="stylesheet" href=""crossorigin="anonymous">


  • i've deleted part of the link ,but you can have a new full-api-link here

Side-Question/ Please think with me, What if you wanna use more apis?
Answer/ aooch A head tag filled with blocks of multiple unclean lines.

the Beautiful Laravel

give yourself [5-minutes] : eyes-looking-to-the-ceiling. Work your mind to create a feature that can clean up our code? you can use a paper and a pencil.


now We're talking about a helper feature or functionality & Yeaaa for sure this is one tiny purpose of using Laravel Custom Built Helpers. So let's get back to our empty file ( app/helpers.php ) and start adding some code to it as shown:


function fontawesomeloader(){
echo '<link rel="stylesheet" href=""crossorigin="anonymous">';


  • i prefer using snake-case naming style for Laravel helpers.

now let's get back to our layout.blade.php please Erase the previous link tag was added in [Point: 2] , Then please replace it with the helpers method-name we added in [Point: 3-2] fontawesomeloader(). Now Refresh your page. And Ohhh nothing works what's wrong ?!!

  • laravel will throw an exception saying it can't find any function called fontawesomeloader(). let's fix that.
  • remember we declare the helpers function name like this {!! fontawesomeloader() !!}

please goto a file within your main project directory called (composer.json) , you'll find it in a directory like this (LaravelProjectName/composer.json).

Within file please search for "autoload": {

now edit the code inside the "autoload" object to be like the following code


"autoload": {
"psr-4": {
"App\\": "app/"
"classmap": [


  • we added our helper.php file location inside the files-Array ,This is called __ Registering __ your Helpers.

Now you've registered your helpers.php file and open it for random call/access within anyfile inside your project directory.

and Oaoooo , nothing works AGAIN.

One final step to turn it on forever. Please go to your Terminal. and cd to your project directory then execute the following command


composer dump-autoload

Great News,your helpers are up and running & you can easily add as many methods as you like.

You've done a great job learning and setting up your first Laravel Helpers.
and am very happy and proud of you.


Isn't Laravel so beautiful ?


Thanks for your time and patience.

i hope i was useful to you. please try it out and modify the code i wrote. Develop your own helpers and comment it out here if you like.

Top comments (6)

gabe profile image

Laravel looks so nice. I’ve been dying to try it out, was considering switching my current cms from grav to octobercms just so I can give laravel a real shot!

Any recommended readings for those new to laravel and php in general?

__mfarag profile image
Mina Farag

You know, you will never regret trying laravel. It’s a powerful , clean and beautiful platform.

You can find useful laravel resources in :

  • /documentaries
gabe profile image

Gave OctoberCMS a try tonight and got a chance to use laravel. I’m hooked, going to build out a custom template and use that as a new blog. Thank you for this!

Thread Thread
__mfarag profile image
Mina Farag

OctoberCMS is super painful to me. Actually am a #laravel fan

Thread Thread
gabe profile image

Really? Interesting - mind sharing what you dislike about it?

Thread Thread
__mfarag profile image
Mina Farag

sorry for replying late. but i was away for a while. Actually i hate how OctoberCms messes with the way things organized and functioned. If you were used to MCV pattern and Model-view-controller ways of hierarchy your code, You will find it super weird to deal with so called components and default.htm and so so confusing stuff.

it wasted tons of my hours trying to fix bugs and make it work smoothly for one of my customers. as a senior developer am not recommending it anymore specially for people with a huge laravel background.