Menu

## Macro

Macro.php : 23

Trait Macros.

Allows users to register macros within the Carbon class.

### Table of Contents

#### Methods

genericMacro() : void
  Register a custom macro.
getLocalMacro() : callable|null
  Get the raw callable macro registered globally or locally for a given name.
getMacro() : callable|null
  Get the raw callable macro registered globally for a given name.
hasLocalMacro() : bool
  Checks if macro is registered globally or locally.
hasMacro() : bool
  Checks if macro is registered globally.
macro() : void
  Register a custom macro.
resetMacros() : void
  Remove all macros and generic macros.

### Methods

#### genericMacro()

Macro.php : 65

Register a custom macro.

`public static genericMacro(callable $macro[, int $priority = 0 ]) : void`

##### Parameters

$macro : callable
$priority : int = 0

  marco with higher priority is tried first

#### getLocalMacro()

Macro.php : 103

Get the raw callable macro registered globally or locally for a given name.

`public getLocalMacro(string $name) : callable|null`

##### Parameters

$name : string

##### Return values

callable|null

#### getMacro()

Macro.php : 85

Get the raw callable macro registered globally for a given name.

`public static getMacro(string $name) : callable|null`

##### Parameters

$name : string

##### Return values

callable|null

#### hasLocalMacro()

Macro.php : 93

Checks if macro is registered globally or locally.

`public hasLocalMacro(string $name) : bool`

##### Parameters

$name : string

##### Return values

bool

#### hasMacro()

Macro.php : 77

Checks if macro is registered globally.

`public static hasMacro(string $name) : bool`

##### Parameters

$name : string

##### Return values

bool

#### macro()

Macro.php : 44

Register a custom macro.

`public static macro(string $name, callable|null $macro) : void`

Pass null macro to remove it.

##### Parameters

$name : string
$macro : callable|null

##### Tags

example

      $userSettings = [
        'locale' => 'pt',
        'timezone' => 'America/Sao_Paulo',
      ];
      Carbon::macro('userFormat', function () use ($userSettings) {
        return $this->copy()->locale($userSettings['locale'])->tz($userSettings['timezone'])->calendar();
      });
      echo Carbon::yesterday()->hours(11)->userFormat();

#### resetMacros()

Macro.php : 52

Remove all macros and generic macros.

`public static resetMacros() : void`

## Search results