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!

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)

Available colors:

primary secondary success warning error info

purple pink blue green yellow red gray

use MoonShine\UI\Fields\Preview;
 
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
)

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

use MoonShine\UI\Fields\Preview;
 
Preview::make('Active')
->boolean(hideTrue: false, hideFalse: false)

Link

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 - 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.

use MoonShine\UI\Fields\Preview;
 
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.

use MoonShine\UI\Fields\Preview;
 
Preview::make('Thumb')
->image()

preview_image preview_image_dark