Skip to content

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.

License

Notifications You must be signed in to change notification settings

wilmersaz/LaravelHelpers

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Standard creation and use of helpers within the Laravel PHP Framework | v1.x

⚙️ This library is compatible with Laravel versions 8.0 and above ⚙️

Laravel 8.0+ Laravel 9.0+ Laravel 10.0+

Logo

----Documentación En Español----

Table of Contents

Introduction

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.

Installation

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.

Usage

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.

Calling Helpers

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();

Creating a New Category

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.

Creator

License

This project is under the MIT License.

About

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%