Standardization creation of Helpers outside of those supplied by the … #100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why accept this contribution?
I have worked for many years with Laravel, and I have seen that in almost all projects the Helpers are created in different ways in different paths and folders, I have seen people who start using the Framework that when they see the syntax of a Helper similar to that of a PHP own function try to use the function on another system. After seeing this I wanted to standardize the process of creating Helpers, I would like to provide the feature and that a standard for creating helpers for developing systems, easy to use and implement, can be included in the official documentation.
Originally created library code repository.
https://github.com/rmunate/LaravelHelpers
If my contribution becomes useful, I promise to update the documentation in the framework's helpers section.
Manual
Standard Creation and Use of Helpers within (Laravel PHP Framework) | v1.x
It's time to standardize how to create and use them
---- Documentación En Español ----
Standard creation and use of helpers within the Laravel framework through classes, a simple, efficient, and elegant way to execute your application's own methods from any class or view.
Installation via Composer
Ways to Use It
Once you have installed the dependency within your project, you can start the structure of your helpers using the following command:
This will create a folder named
Helpers
withinApp/
where you will find the suggested standard classes for creating your own helpers. It is recommended to create helpers depending on their category of use.For example, if you are going to create a function that adjusts text strings according to some application-specific requirement, you should create the method inside the
Strings
class.The methods you create within the chosen class should always have their method name starting with the first word in lowercase and from the second word in uppercase (camelCase).
Now that you have defined the methods, you can call them from anywhere in your application using the following syntax: start with the word
Helper
, followed by the static call::
, then write the lowercase name of the helper category, in this case,strings
, and finally the method name inPascalCase
.Example of using the
myMethod
method:Controllers or Classes:
Views or Components:
Similarly, since the place where you write the helpers is a class, you can directly call the class that needs to be extended or imported for use. For this purpose, the
instance()
method is included, and you can use it as follows:If you want a category that is not provided by the existing classes, no problem! Just execute the following command to create the new category:
# Replace "Category" with the name you require php artisan create:helper Category
An efficient, clear, clean, and elegant way to create and manage your own functions.
Creator