mpesic381/laravel-placeholders

Find and Replace placeholder strings in Laravel 8

1.1.0 2024-04-08 11:13 UTC

This package is auto-updated.

Last update: 2024-11-08 12:30:05 UTC


README

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require mpesic381/laravel-placeholders

Then you will need to run these commands in the terminal in order to copy the config file

php artisan vendor:publish --provider="MPesic381\Placeholders\PlaceholdersServiceProvider"

Usage

use Placeholders;

// Basic
Placeholders::parse("I like [fruit]s and [veg]s", [
	'fruit' => 'orange',
	'veg' => 'cucumber'
]); //I like oranges and cucumbers

// Globally
Placeholders::set("fruit", "apple");
Placeholders::set("veg", "carrot");
Placeholders::parse("I like [fruit]s and [veg]s"); // I like apples and carrots

Style

// Change the style
Placeholders::setStyle("{{", "}}");
Placeholders::parse("I like {{fruit}}s and {{veg}}s", [
	'fruit' => 'lemon',
	'veg' => 'string bean'
]); //I like lemons and string beans

Behaviors

// Throw an error if one is missed
Placeholders::setBehavior('error')
Placeholders::parse("I like [fruit]s and [veg]s", [
	'fruit' => 'orange',
]); //Throws an Exception: Could not find a replacement for [veg]

// Delete the placeholder from the output if it is missing.
Placeholders::setBehavior('skip')
Placeholders::parse("I like [fruit]s and [veg]s", [
	'fruit' => 'orange',
]); // I like oranges and s

Placeholders::setBehavior('preserve')
Placeholders::parse("I like [fruit]s and [veg]s", [
	'fruit' => 'orange',
]); // I like oranges and [veg]s

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.