jimchen/laravel-macro

Laravel Macro Helper

Maintainers

👁 jimchen

Package info

github.com/JimChenWYU/laravel-macro

pkg:composer/jimchen/laravel-macro

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

v0.1.0 2018-09-13 06:02 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT dee9d8d0b7ea6725612b36973fe159da52eeb4e0

  • JimChen <18219111672.woop@163.com>

This package is auto-updated.

Last update: 2026-06-18 06:50:57 UTC


README

👁 Build Status

Laravel Macro Helper

Installing

$ composer require jimchen/laravel-macro -vvv

The package will automatically register itself.

If you use Laravel 5.1.*, you can add the service provider to the providers array in config/app.php.

JimChen\Macro\LaravelMacroServiceProvider::class,

Usage

You should publish the config file to add macros.

$ php artisan vendor:publish --provider="JimChen\Macro\LaravelMacroServiceProvider"

Binding macro class to macroable class in config/macro.php.

return [
 'macros' => [
 'Illuminate\Support\Arr' => [
 'App\Macros\Arr',
 ]
 ],
];

Define macro file, app/Macros/Arr1.php.

namespace App\Macro;

class Arr
{
 public static function merge($a, $b)
 {
 return array_merge($a, $b);
 }
}

Using in anywhere if you need. Great!

For example in app/routes/web.php

use Illuminate\Support\Arr;

Route::get('/', function () {
 $foo = [1, 2];
 $bar = [3, 4];
 
 $result = Arr::merge($foo, $bar);
 
 dd($result); // [1, 2, 3, 4]
});

License

MIT