mpesic381 / laravel-placeholders
Find and Replace placeholder strings in Laravel 8
Installs: 3 716
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0|^8.1|^8.2
- illuminate/support: ^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-11-08 12:30:05 UTC
README
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
- tylercd100 - This package is based on his one
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.