Support the ongoing development of →
Last updated 2 years ago.

I searched for the info for some while, i did not find much so i decided to go this way.
1: I created folder app/Helpers
2: In app/Providers I created new provider file HelperServiceProvider.php
3: In this file I registered all helpers classes I need

$this->app->bind('dateHelper', function()
    return new \App\Helpers\DateHelper;
... etc

4: In config/app.php I added this new provider


5: Then you need to create Facade to be availalbe to use this helper in view. You find the info about how to create Facade on offical site

Last updated 9 years ago.


If your helper functions are similar to the way laravel 5 ones work, i.e Illuminate/Support/helpers.php you could just create a helpers.php and have composer do the autoloading for you.

Edit your composer.json file and add the file to the autoloading key. In my example my app is called Tasky so just add the files key and reference helpers.php.

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

That way you just create your file inside app/Support/helpers.php and all your common function based view helpers or other helpers can go here. If you take the class based approach then the above is great.

Also then remember to just run the following once.

$ composer dumpautoload
Last updated 9 years ago.

I usually create a Facade which does that for me. E.g. I have a Info facade to render modals or which I call to add messages that should be shown with the next request. Then I have a CurrentUser facade which acts as a proxy to some of my user model functions. It automatically checks if the user is logged in and if not just returns nothing this way I save some if statements in my views:

      <a href="admin/link">Admin</>

{{-- Becomes --}}

   <a href="admin/link">Admin</>

{{-- Display a deletion modal which asks for confirmation to delete that record --}}
{!! Info::deleteModal($user->name, $user->name, route('admin.user.delete', $user)) !!}

The beauty of facades is that you can render views in then (e.g. my modal view) and then return the rendered view.

Last updated 9 years ago.



I think this is the perfect solution I've found so far:

Last updated 9 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.