Fields

Preview

Basics

Contains all Basic Methods.

With the Preview field, you can display text data from any field in the model or generate any content.

The field is NOT intended for data input/modification!

 namespaces
use MoonShine\UI\Fields\Preview;
 
Preview::make(
'Preview',
'preview',
static fn() => fake()->realText()
)
 namespaces
use MoonShine\UI\Fields\Preview;
 
Preview::make(
'Preview',
'preview',
static fn() => fake()->realText()
)

preview preview_dark

View Methods

Badge

The badge() method allows you to display the field as a badge, for example, to show the order status. The method accepts a parameter as a string or a closure with the badge color.

badge(string|Closure|null $color = null)
badge(string|Closure|null $color = null)

Available colors:

primary secondary success warning error info purple pink blue green yellow red gray

Preview::make('Status')
->badge(fn($status, Field $field) => $status === 1 ? 'green' : 'gray')
Preview::make('Status')
->badge(fn($status, Field $field) => $status === 1 ? 'green' : 'gray')

Boolean

The boolean() method allows you to display the field as a label (green or red) for boolean values.

boolean(
mixed $hideTrue = null,
mixed $hideFalse = null
)
boolean(
mixed $hideTrue = null,
mixed $hideFalse = null
)

The hideTrue and hideFalse parameters allow hiding the label for the values.

Preview::make('Active')
->boolean(hideTrue: false, hideFalse: false)
Preview::make('Active')
->boolean(hideTrue: false, hideFalse: false)

The link() method allows you to display the field as a link.

link(
string|Closure $link,
string|Closure $name = '',
?string $icon = null,
bool $withoutIcon = false,
bool $blank = false,
)
link(
string|Closure $link,
string|Closure $name = '',
?string $icon = null,
bool $withoutIcon = false,
bool $blank = false,
)
  • $link - URL of the link,
  • $name - text of the link,
  • $icon - name of the icon,
  • $withoutIcon - do not show the link icon,
  • $blank - open the link in a new tab.

For more details, refer to the Icons section.

Preview::make('Link')
->link('https://moonshine-laravel.com', blank: false),
 
Preview::make('Link')
->link(fn($link, Field $field) => $link, fn($name, Field $field) => 'Go')
Preview::make('Link')
->link('https://moonshine-laravel.com', blank: false),
 
Preview::make('Link')
->link(fn($link, Field $field) => $link, fn($name, Field $field) => 'Go')

preview_all preview_all_dark

Image

The image() method allows you to convert a URL into a thumbnail with an image.

Preview::make('Thumb')
->image()
Preview::make('Thumb')
->image()

preview_image preview_image_dark