Looking to hire Laravel developers? Try LaraJobs

laravel-placeholders maintained by mpesic381

Description
Find and Replace placeholder strings in Laravel 8
Author
Last update
2024/04/08 13:13 (dev-master)
License
Downloads
8 987

Comments
comments powered by Disqus

Find and Replace placeholder strings in Laravel 8 and newer

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.