halaabusalim/laravel-dynamic-placeholder

A Laravel package to generate context-aware placeholder content.

Maintainers

Package info

github.com/HalaSalim77/laravel-dynamic-placeholder

pkg:composer/halaabusalim/laravel-dynamic-placeholder

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2025-07-28 18:21 UTC

This package is auto-updated.

Last update: 2026-03-28 19:51:29 UTC


README

A Laravel package to generate context-aware placeholder content for your applications.

Installation

  1. Install the package via Composer:
composer require halaabusalim/laravel-dynamic-placeholder
  1. Publish the configuration file:
php artisan vendor:publish --provider="Halaabusalim\LaravelDynamicPlaceholder\DynamicPlaceholderServiceProvider" --tag="config"

Usage

Using the Facade

use Halaabusalim\LaravelDynamicPlaceholder\Facades\DynamicPlaceholder;

// Generate text placeholders
$productName = DynamicPlaceholder::text('ecommerce.product_name');
$blogTitle = DynamicPlaceholder::text('blog.title');

// Generate number placeholders
$price = DynamicPlaceholder::number('ecommerce.price');

// Generate image placeholders
$imageUrl = DynamicPlaceholder::image('product-image');

Using Dependency Injection

use Halaabusalim\LaravelDynamicPlaceholder\DynamicPlaceholder;

class ProductController extends Controller
{
    public function __construct(private DynamicPlaceholder $placeholder)
    {
    }

    public function index()
    {
        $productName = $this->placeholder->text('ecommerce.product_name');
        $price = $this->placeholder->number('ecommerce.price');
        
        return view('products.index', compact('productName', 'price'));
    }
}

Configuration

The package comes with a configuration file that you can customize. Edit config/dynamic-placeholder.php:

return [
    'contexts' => [
        'ecommerce' => [
            'product_name' => ['Laptop', 'Smartphone', 'Headphones', 'Smartwatch'],
            'description' => [
                'High-performance device for professionals.',
                'Sleek design with cutting-edge technology.',
                'Perfect for everyday use.'
            ],
            'price' => ['min' => 50, 'max' => 1000],
        ],
        'blog' => [
            'title' => ['Top 10 Tips for Success', 'How to Start a Blog', 'The Future of Tech'],
            'content' => ['Lorem ipsum dolor sit amet...', 'In this article, we explore...'],
        ],
    ],
];

Methods

text(string $context): string

Returns a random text from the configured context.

number(string $context): float

Returns a random number within the configured range.

image(string $context): string

Returns a placeholder image URL (currently uses via.placeholder.com).

Testing

Running Tests

  1. Unit Tests with PHPUnit:
./vendor/bin/phpunit
  1. Manual Testing:
php test-manual.php

Test Coverage

The test suite covers:

  • ✅ Text placeholder generation
  • ✅ Number placeholder generation with ranges
  • ✅ Image placeholder URL generation
  • ✅ Error handling for missing contexts
  • ✅ Facade functionality
  • ✅ Service provider registration
  • ✅ Configuration merging
  • ✅ Singleton pattern verification

License

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