PHP code example of m2collective / laravel-value-types
1. Go to this page and download the library: Download m2collective/laravel-value-types library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
m2collective / laravel-value-types example snippets
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,
]);
}
}