⚙️ This library is compatible with Laravel versions 8.0 and above ⚙️
----Documentación En Español----
Empower your Laravel journey: Unleash the power of helpers! Unlock a world of possibilities with our standard creation and seamless utilization of helpers within the Laravel framework. Our solution offers a simple, efficient, and elegant way to execute your application's custom methods from any class or view, making development a breeze. Supercharge your Laravel project and elevate your coding experience with our Helper Library.
We will guide the use of Helpers by organizing them into categories.
For many years, I have been using Laravel, and I believe it is the framework that brings the best out of PHP. However, the creation of Helpers has not been standardized within this framework. Therefore, I decided to create a standard and implement it in various systems and companies for which I have worked.
Now you have it as a library!
It's time to standardize how to create and use them.
To install the package via Composer, run the following command:
composer require rmunate/laravel_helpers
This will download the latest available version of the package.
After installing the dependency in your project, you can generate the initial structure of the helpers by executing the following command:
php artisan generate:helpers
This will create a folder called Helpers
inside App/
, where you will find suggested standard classes for creating your own helpers.
The structure of the Helpers
folder will be as follows:
app/
└── Helpers/
└── DataTime.php
└── File.php
└── General.php
└── Html.php
└── Security.php
└── Strings.php
//...
Each class represents a category of helpers. The classes will not have methods defined; you will start defining the ones your application requires.
You can organize your helpers into different categories by creating dedicated classes for each of them. For example, if you want to create functions related to text strings, you can use the Strings
class.
To call the helpers from anywhere in your application, use the following syntax:
-
Controllers or Classes:
use Helper; Helper::categoryNameMethod();
-
Views or Components:
{{ Helper::categoryNameMethod() }}
You can also import and directly use the class of the required category by using the helpers()
method. For example:
use App\Helpers\Strings;
// Using the helpers() method
Strings::helpers()->methodName();
If you want to create a new category of helpers, execute the following command:
php artisan create:helper CategoryName
Replace CategoryName
with the desired name for the new category. The name must not contain numbers, accents, or special characters.
- 🇨🇴 Raúl Mauricio Uñate Castro
- Email: raulmauriciounate@gmail.com
This project is under the MIT License.