PHPackages                             lbausch/build-metadata-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lbausch/build-metadata-laravel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lbausch/build-metadata-laravel
==============================

v0.5.0(1mo ago)02.8k↓83%MITPHPPHP ^8.3CI passing

Since Oct 27Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/lbausch/build-metadata-laravel)[ Packagist](https://packagist.org/packages/lbausch/build-metadata-laravel)[ RSS](/packages/lbausch-build-metadata-laravel/feed)WikiDiscussions main Synced yesterday

READMEChangelog (5)Dependencies (12)Versions (7)Used By (0)

Build Metadata for Laravel
===========================

[](#build-metadata-for-laravel-)

[![tests](https://github.com/lbausch/build-metadata-laravel/actions/workflows/tests.yml/badge.svg)](https://github.com/lbausch/build-metadata-laravel/actions/workflows/tests.yml/badge.svg) [![codecov](https://camo.githubusercontent.com/6652bdde3ab5ab802d4bdd27f85dbce6c3bd0d15606979590607c74d9c41e57b/68747470733a2f2f636f6465636f762e696f2f67682f6c6261757363682f6275696c642d6d657461646174612d6c61726176656c2f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://camo.githubusercontent.com/6652bdde3ab5ab802d4bdd27f85dbce6c3bd0d15606979590607c74d9c41e57b/68747470733a2f2f636f6465636f762e696f2f67682f6c6261757363682f6275696c642d6d657461646174612d6c61726176656c2f6272616e63682f6d61696e2f67726170682f62616467652e737667)

Save arbitrary build metadata (commit SHA, build date, ...), deploy them along with your application and retrieve them at runtime when required.

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Configuration](#configuration)
    - [Saving Build Metadata](#saving-build-metadata)
    - [Deployer Recipe](#deployer-recipe)
    - [Using Build Metadata at Runtime](#using-build-metadata-at-runtime)
    - [Callbacks](#callbacks)
        - [beforeCaching](#beforecaching)
        - [afterRetrieving](#afterretrieving)
    - [Events](#events)
        - [CachingBuildMetadata](#cachingbuildmetadata)
        - [CachedBuildMetadata](#cachedbuildmetadata)

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 12+

Installation
------------

[](#installation)

```
composer require lbausch/build-metadata-laravel
```

Usage
-----

[](#usage)

### Configuration

[](#configuration)

If the default configuration doesn't suit your needs, you may publish the [configuration file](config/build-metadata.php):

```
php artisan vendor:publish --provider=Lbausch\\BuildMetadataLaravel\\ServiceProvider
```

### Saving Build Metadata

[](#saving-build-metadata)

When deploying your application, e.g. utilizing a CI/CD pipeline, the following command writes build metadata to the configured file:

```
php artisan buildmetadata:save BUILD_REF=$CI_COMMIT_SHA BUILD_DATE=$(date +%s)
```

Build metadata are indefinitely cached, so either the application cache needs to be cleared during deployment or the following command may be used:

```
php artisan buildmetadata:clear
```

### Deployer Recipe

[](#deployer-recipe)

This package ships with a Deployer recipe which provides tasks to handle the build metadata.

```
