Links and images
Two field types hydrate into value objects rather than raw scalars, so your block's view never has to reassemble them itself.
LinkValue
The Link field type hydrates into WeArePixel\Inlay\Support\LinkValue, a plain readonly value object with label, url, and openInNewTab:
use WeArePixel\Inlay\Attributes\Link;
use WeArePixel\Inlay\Support\LinkValue;
final class Hero extends Component implements InlayBlock
{
public function __construct(
#[Link(label: 'Call to action')]
public ?LinkValue $cta = null,
) {}
}
@if ($cta)
<a href="{{ $cta->url }}" @if ($cta->openInNewTab) target="_blank" @endif>{{ $cta->label }}</a>
@endif
URL scheme safety
Only http://, https://, mailto:, and relative (scheme-less) URLs are ever persisted. Anything else - javascript:..., for example - is rejected before it reaches storage, at the point an editor saves it. You can render $cta->url directly into an href attribute without adding your own scheme check.
ImageValue
The Image field type hydrates into WeArePixel\Inlay\Support\ImageValue, not the bare disk-relative path the editor stores - so your block's view never has to know which disk an upload landed on or call Storage::disk(...)->url(...) itself. ImageValue::__toString() resolves the real URL, so echoing it directly is correct:
use WeArePixel\Inlay\Attributes\Image;
use WeArePixel\Inlay\Support\ImageValue;
final class Hero extends Component implements InlayBlock
{
public function __construct(
#[Image(label: 'Photo')]
public ?ImageValue $photo = null,
) {}
}
@if ($photo)
<img src="{{ $photo }}" alt="">
@endif
Nullable vs. non-nullable
Type the parameter ?ImageValue $photo = null (as above) if you want "no image" to behave like a genuinely absent value - @if ($photo) then works exactly as you'd expect.
A non-nullable ImageValue $photo = new ImageValue() still gets a real instance even with nothing uploaded, since PHP objects are always truthy regardless of their contents - check $photo->isEmpty() explicitly in that case, not @if ($photo).
Call $photo->url() instead of relying on __toString() if you need the resolved URL somewhere other than a plain Blade {{ }} echo - an attribute built with Str::of(), for example.