Looking to hire Laravel developers? Try LaraJobs

laravel-value-types maintained by m2collective

Author
Last update
2026/07/31 16:00 (dev-main)
License
Downloads
0

Comments
comments powered by Disqus

Value Types

Laravel PHP


Installation

You can install the package via composer:

composer require m2collective/laravel-value-types

The package will automatically register itself.

Usage

An example of using a package with the facades:

use Illuminate\View\View;
use M2Collective\ValueTypes\Contracts\ArrayValue;
use M2Collective\ValueTypes\Contracts\StringValue;
use M2Collective\ValueTypes\Facades\ArrayValue as ArrayValueFacade;
use M2Collective\ValueTypes\Facades\StringValue as StringValueFacade;

final class Example 
{
    /**
     * @var ArrayValue 
     */
    protected ArrayValue $title;
    
    /**
     * @var StringValue 
     */
    protected StringValue $subtitle;
    
    /**
     * @param string|null $titleText
     * @param string|null $titleHref
     */
    public function __construct(
        ?string $titleText = null,
        ?string $titleHref = null,
        ?string $subtitle = null
    ) {
        $this->title = ArrayValueFacade::set([
              'href' => $titleHref ?? '#',
              'text' => $titleText ?? 'Text'
        ]);
        
        $this->subtitle = StringValueFacade::set($subtitle ?? 'Subtitle')
    }
    
    /**
     * @return View
     */
    public function render(): View
    {
        return view('example', [
            'title' => $this->title,
            'subtitle' => $this->subtitle,
        ]);
    }
}
<a class="title" href="{{ $title->get('href') }}" title="{{ $title->get('text') }}">
    {{ $title->get('text') }}
</a>
<p class="subtitle">
    {{ $subtitle->get() }}
</p>

License

The MIT License (MIT). Please see the License file for more information.