dimanche 2 avril 2017

Custom helper classes in Laravel 5.4

I have some helper classes in app/Helpers. How do I load these classes using a service provider to use them in blade templates?

e.g. If I have a class CustomHelper that contains a method fooBar() :

<?php

nampespace App\Helpers;

class CustomHelper
{
    static function fooBar()
    {
        return 'it works!';
    }
}

I want to be able to do something like this in my blade templates:



instead of doing this:



P.S: @andrew-brown's answer in Best practices for custom helpers on Laravel 5 deals with non-class files. It would be nice to have a class based solution so that the helper functions can be organized among classes.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire