PHP Classes

Laravel Macro Example: Example of macro service to use in view templates

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 31 All time: 11,095 This week: 104Up
Version License PHP version Categories
laravel-macros 1.0The PHP License5PHP 5, Libraries, Templates, Design P...
Description 

Author

This package provides an example of a macro service in view templates.

It comes with a Laravel service class that registers a macro class that can generate HTML in a view template.

When applications use view templates to invoke the registered macro class, a call to that class generates the HTML code depending on the values passed to the macro function.

In this package, the example macro class can generate a form select input to let users pick a bank from a static list array.

Innovation Award
PHP Programming Innovation award nominee
September 2022
Number 9
A macro is an abbreviated form to represent information that may be long.

Macros can help save time for developers that need to write code for the different parts of their applications.

This package provides an example of how to use macros in Laravel applications by showing how to create a macro class that generates HTML for options of a form select input that has many options, for instance, a list of supported banks.

This macro class can save a lot of time for developers that need to insert the same type of form select input in the output of their applications' Laravel view templates.

Manuel Lemos
Picture of Nahidul Hasan
  Performance   Level  
Name: Nahidul Hasan <contact>
Classes: 16 packages by
Country: Bangladesh Bangladesh
Age: ???
All time rank: 257332 in Bangladesh Bangladesh
Week rank: 170 Up2 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 7x

Documentation

Laravel-Macros

Latest Stable Version Total Downloads Latest Unstable Version License

> A Simple package for using Macros in Laravel

Installation

Requirements

- PHP >= 5.6.4 - Laravel >= 5.5

Installing

Run the following commands

composer require nahidulhasan/laravel-macros

php artisan vendor:publish

Basic Usage

A new class is created in App/Services folder named Macros.php. Here you have to add your code.

For example, I have added bank list.

Now you can call Form::selectBank() in any view, and have it display a nice list of Bank list to select from.

You can specify the parameters as the input name, default selected value, and array of options.

Here is the example :

<div class="form-group">

<label for="bank_name">Bank Name</label>

{{ Form::selectBank("bank_name", $merchant['paymentInfo']->bank_name ?? null,["class"=>"form-control"]) }}

</div>

If you want to learn more about macros and want to configure without using package, please read this blog

License

Laravel-Macros for Laravel is open-sourced software licensed under the MIT license


  Files folder image Files (5)  
File Role Description
Files folder imagesrc (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  src  
File Role Description
  Plain text file Macros.php Class Class source
  Plain text file MacrosServiceProvider.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:31
This week:0
All time:11,095
This week:104Up