PHPackages                             rdcstarr/laravel-placeholders - 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. rdcstarr/laravel-placeholders

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

rdcstarr/laravel-placeholders
=============================

Laravel Placeholders

v1.0.1(5mo ago)01MITPHPPHP ^8.3

Since Nov 26Pushed 5mo agoCompare

[ Source](https://github.com/rdcstarr/laravel-placeholders)[ Packagist](https://packagist.org/packages/rdcstarr/laravel-placeholders)[ Docs](https://github.com/rdcstarr/laravel-placeholders)[ RSS](/packages/rdcstarr-laravel-placeholders/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (2)Used By (0)

Laravel Placeholders
====================

[](#laravel-placeholders)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d325e79ef7a42ea10af07101047ec6703b9d29c3c20132898387bafe626fb99f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72646373746172722f6c61726176656c2d706c616365686f6c646572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rdcstarr/laravel-placeholders)[![GitHub Tests Action Status](https://camo.githubusercontent.com/6e1c2e113546051c206300b3c175e21a2b4cb45a9f4d8a2aaf66f923bcd3ffe1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72646373746172722f6c61726176656c2d706c616365686f6c646572732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/rdcstarr/laravel-placeholders/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/34d3bdc8a764c7400286642ca09a93f1c490ddb0aedf022bb7d4034ac59ef5b8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72646373746172722f6c61726176656c2d706c616365686f6c646572732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/rdcstarr/laravel-placeholders/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1f077eef6c5141c1a7138f06e80994d8615ac0a0c6bce172041f4b5ba180c5a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72646373746172722f6c61726176656c2d706c616365686f6c646572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rdcstarr/laravel-placeholders)

A powerful Laravel package for managing dynamic placeholders in your strings with support for multiple transformations, date/time helpers, and custom values.

Features
--------

[](#features)

- 🔄 **Case Transformations**: Automatic uppercase, lowercase, and title case support
- 📅 **Date &amp; Time Placeholders**: Built-in support for dates, times, and timestamps
- 🎨 **Custom Placeholders**: Define your own placeholders globally or per-usage
- 🔒 **Auto-Protection**: Values containing {{}} are automatically protected
- ⚡ **Closure Support**: Use closures for advanced placeholder transformations
- 🎯 **Stringable Objects**: Handle custom objects (Money, Date, etc.) seamlessly
- 🌐 **Laravel Integration**: Inspired by Laravel's Translator for familiar patterns

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

[](#installation)

You can install the package via composer:

```
composer require rdcstarr/laravel-placeholders
```

### Automatic Installation (Recommended)

[](#automatic-installation-recommended)

Run the install command to publish and run the migrations:

```
php artisan placeholders:install
```

### Manual Installation

[](#manual-installation)

Alternatively, you can install manually:

1. Publish the config file:

```
php artisan vendor:publish --tag=placeholders-config
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Rdcstarr\Placeholders\Facades\Placeholders;

// Simple replacement
$text = "Hello {{name}}!";
$result = Placeholders::parse($text, ['name' => 'John']);
// Output: "Hello John!"

// Or using the helper function
$result = placeholders("Hello {{name}}!", ['name' => 'John']);
// Output: "Hello John!"
```

### Case Transformations

[](#case-transformations)

The package supports automatic case transformations:

```
$text = "User: {{name}}, Email: {{Email}}, ID: {{ID}}";
$result = placeholders($text, [
    'name' => 'john doe',
    'email' => 'JOHN@EXAMPLE.COM',
    'id' => 'abc123'
]);
// Output: "User: john doe, Email: John@example.com, ID: ABC123"
```

#### Available Formats

[](#available-formats)

- `{{key}}` - exact value (lowercase)
- `{{Key}}` - first letter uppercase
- `{{KEY}}` - all uppercase

### Default Placeholders

[](#default-placeholders)

The package provides built-in date, time, and application placeholders:

```
$text = "Today is {{date}} at {{time}}";
$result = placeholders($text);
// Output: "Today is 2025-11-26 at 14:30"
```

#### Available Default Placeholders

[](#available-default-placeholders)

**Date**:

- `{{year}}` - 2025
- `{{month}}` - 11
- `{{day}}` - 26
- `{{date}}` - 2025-11-26

**Time**:

- `{{hour}}` - 14
- `{{minute}}` - 30
- `{{time}}` - 14:30
- `{{datetime}}` - 2025-11-26 14:30:00

**Application**:

- `{{app_name}}` - Your app name
- `{{app_url}}` - Your app URL

### Custom Placeholders

[](#custom-placeholders)

#### Using Config

[](#using-config)

Define placeholders in your `config/placeholders.php`:

```
return [
    'placeholders' => [
        'company_name' => 'Acme Corp',
        'support_email' => 'support@acme.com',
        'phone' => '+1234567890',
    ],
];
```

#### Using Helper Functions

[](#using-helper-functions)

```
// Set a single placeholder
set_placeholder('user_name', 'John Doe');

// Set multiple placeholders
set_placeholder([
    'company' => 'Acme Corp',
    'year' => 2025,
]);
```

#### Using the Facade

[](#using-the-facade)

```
use Rdcstarr\Placeholders\Facades\Placeholders;

Placeholders::addCustomPlaceholder('company', 'Acme Corp');
Placeholders::setCustomPlaceholders([
    'email' => 'info@acme.com',
    'phone' => '+1234567890',
]);
```

### Closure Support

[](#closure-support)

Use closures for advanced transformations with `content` syntax:

```
$text = "The title is important";
$result = placeholders($text, [
    'bold' => function($content) {
        return "{$content}";
    }
]);
// Output: "The title is important"
```

### Stringable Objects

[](#stringable-objects)

Handle custom objects seamlessly by registering handlers:

```
use App\ValueObjects\Money;
use Rdcstarr\Placeholders\Facades\Placeholders;

// Register handler for Money objects
Placeholders::stringable(Money::class, function($money) {
    return $money->format();
});

// Or use the helper
stringable_placeholder(Money::class, fn($money) => $money->format());

// Now Money objects work automatically
$text = "Total: {{price}}";
$result = placeholders($text, ['price' => new Money(1000, 'USD')]);
// Output: "Total: $10.00"
```

### Auto-Protection

[](#auto-protection)

Values containing `{{}}` are automatically protected from being interpreted as placeholders:

```
$userContent = "My template uses {{price}} syntax";
$result = placeholders("User says: {{content}}", [
    'content' => $userContent
]);
// Output: "User says: My template uses {{price}} syntax"
// The {{price}} in user content is preserved!
```

### Managing Custom Placeholders

[](#managing-custom-placeholders)

```
use Rdcstarr\Placeholders\Facades\Placeholders;

// Get all custom placeholders
$all = Placeholders::getCustomPlaceholders();

// Clear all custom placeholders
Placeholders::clearCustomPlaceholders();
```

Advanced Examples
-----------------

[](#advanced-examples)

### Email Template

[](#email-template)

```
$template = "Dear {{Name}},\n\n"
    . "Thank you for contacting {{company_name}}.\n"
    . "We received your message on {{date}} at {{time}}.\n\n"
    . "Our team will respond to {{email}} within 24 hours.\n\n"
    . "Best regards,\n{{company_name}} Team";

set_placeholder('company_name', 'Acme Corp');

$result = placeholders($template, [
    'name' => 'john doe',
    'email' => 'john@example.com',
]);
```

### Dynamic Content

[](#dynamic-content)

```
$content = "Welcome to {{app_name}}! Today is {{date}}.";
$result = placeholders($content);
// Output: "Welcome to Laravel! Today is 2025-11-26."
```

### API Response Messages

[](#api-response-messages)

```
$message = "Resource '{{resource}}' created successfully at {{datetime}}";
$result = placeholders($message, ['resource' => 'users']);
// Output: "Resource 'users' created successfully at 2025-11-26 14:30:00"
```

API Reference
-------------

[](#api-reference)

### Helper Functions

[](#helper-functions)

- `placeholders(string $text, array $placeholders = []): string` - Parse and replace placeholders
- `set_placeholder(string|array $key, mixed $value = ''): void` - Add custom placeholder(s)
- `stringable_placeholder(string $class, callable $handler): void` - Register object handler

### Facade Methods

[](#facade-methods)

**Parsing:**

- `Placeholders::parse(string $text, array $placeholders = []): string`

**Custom Placeholders:**

- `Placeholders::setCustomPlaceholders(array $placeholders): void`
- `Placeholders::addCustomPlaceholder(string $key, mixed $value): void`
- `Placeholders::clearCustomPlaceholders(): void`
- `Placeholders::getCustomPlaceholders(): array`

**Stringable Handlers:**

- `Placeholders::stringable(string $class, callable $handler): void`
- `Placeholders::getStringableHandlers(): array`
- `Placeholders::clearStringableHandlers(): void`

Testing
-------

[](#testing)

```
composer test
```

📖 Resources
-----------

[](#-resources)

- [Changelog](CHANGELOG.md) for more information on what has changed recently. ✍️

👥 Credits
---------

[](#-credits)

- [Rdcstarr](https://github.com/rdcstarr) 🙌

📜 License
---------

[](#-license)

- [License](LICENSE.md) for more information. ⚖️

laravel-placeholders
====================

[](#laravel-placeholders-1)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance70

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

167d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e1c8fb375458574d18b5ddf9a8a6116520fb96f719d1e50de8a40fdf3dcae581?d=identicon)[rdcstarr](/maintainers/rdcstarr)

---

Top Contributors

[![rdcstarr](https://avatars.githubusercontent.com/u/42062586?v=4)](https://github.com/rdcstarr "rdcstarr (2 commits)")

---

Tags

laravellaravel-placeholdersRdcstarr

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/rdcstarr-laravel-placeholders/health.svg)

```
[![Health](https://phpackages.com/badges/rdcstarr-laravel-placeholders/health.svg)](https://phpackages.com/packages/rdcstarr-laravel-placeholders)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
