PHP Classes

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2022-09-07 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 26 This week: 1All time: 10,692 This week: 491Up
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: 11 packages by
Country: Bangladesh Bangladesh
Age: ???
All time rank: 277235 in Bangladesh Bangladesh
Week rank: 65 Up5 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 7x

Details

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  
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  /  src  
File Role Description
  Plain text file Macros.php Class Class source
  Plain text file MacrosServiceProvider.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:26
This week:1
All time:10,692
This week:491Up