The field is not intended for entering/changing data!
Make
Using the Preview field you can display text data from any field in the model, or generate text.
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Preview', 'preview', static fn() => fake()->realText())];}//...
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Preview', 'preview', static fn() => fake()->realText())];}//...
Badge
The badge()
method allows you to display a field as an icon, for example to display the status of an order.The method accepts a parameter in the form of a string or closure with an icon 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
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Status')->badge(fn($status, Field $field) => $status === 1 ? 'green' : 'gray')];}//...
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Status')->badge(fn($status, Field $field) => $status === 1 ? 'green' : 'gray')];}//...
Boolean
The boolean()
method allows you to display a 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 you to hide the label for values.
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Active')->boolean(hideTrue: false, hideFalse: false)];}//...
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Active')->boolean(hideTrue: false, hideFalse: false)];}//...
Link
The link()
method allows you to display a 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
- link url,$name
- link text,$icon
- icon name,$withoutIcon
- do not display the link icon,$blank
- open the link in a new tab.
For more detailed information, please refer to the section Icons.
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Link')->link('/', blank: false),Preview::make('Link')->link(fn($link, Field $field) => $link, fn($name, Field $field) => 'Go')];}//...
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Link')->link('/', blank: false),Preview::make('Link')->link(fn($link, Field $field) => $link, fn($name, Field $field) => 'Go')];}//...
Image
The image()
method allows you to transform a url into a thumbnail with an image.
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Thumb')->image()];}//...
use MoonShine\Fields\Preview;//...public function fields(): array{return [Preview::make('Thumb')->image()];}//...