Skip to content

Instantly share code, notes, and snippets.

@dvlpp
Last active December 18, 2019 16:09
Show Gist options
  • Save dvlpp/4b370ace5edb0063383f3660a39fa75f to your computer and use it in GitHub Desktop.
Save dvlpp/4b370ace5edb0063383f3660a39fa75f to your computer and use it in GitHub Desktop.
SpaceshipSharpShow
<?php
class SpaceshipSharpShow extends SharpShow
{
function buildShowFields()
{
$this
->addField(
SharpShowTextField::make("name")
->setLabel("Ship name:")
)->addField(
SharpShowTextField::make("type:label")
->setLabel("Type:")
)->addField(
SharpShowTextField::make("serial_number")
->setLabel("S/N:")
)->addField(
SharpShowTextField::make("brand")
->setLabel("Brand / model:")
)->addField(
SharpShowPictureField::make("picture")
)->addField(
SharpShowTextField::make("description")
->collapseToWordCount(50)
);
}
function buildShowLayout()
{
$this
->addSection('Identity', function(ShowLayoutSection $section) {
$section
->addColumn(7, function(ShowLayoutColumn $column) {
$column
->withSingleField("name")
->withSingleField("type:label")
->withSingleField("serial_number")
->withSingleField("brand");
})
->addColumn(5, function(ShowLayoutColumn $column) {
$column->withSingleField("picture");
});
})
->addSection('Description', function(ShowLayoutSection $section) {
$section
->addColumn(9, function(ShowLayoutColumn $column) {
$column->withSingleField("description");
});
});
}
function find($id): array
{
return $this
->setCustomTransformer("brand", function($value, $spaceship) {
return sprintf("%s / %s", $spaceship->brand ?: '<em>no brand</em>', $spaceship->model ?: '<em>no model</em>');
})
->setCustomTransformer("name", function($value, $spaceship) {
return $spaceship->name;
})
->setCustomTransformer("picture", new SharpUploadModelThumbnailUrlTransformer(140))
->setCustomTransformer("description", (new MarkdownAttributeTransformer())->handleImages(200))
->transform(Spaceship::findOrFail($id));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment