Skip to main content

Model Show

The SuperAdmin\Admin\Show class displays model details in a read-only panel.

A Super Admin detail page showing a single post's fields

Basic Usage​

use App\Models\Post;
use SuperAdmin\Admin\Show;

protected function detail($id)
{
$show = new Show(Post::findOrFail($id));

$show->field('id', 'ID');
$show->field('title', 'Title');
$show->field('body', 'Body');
$show->field('created_at', 'Created');
$show->field('updated_at', 'Updated');

return $show;
}

HTML Escaping​

By default, output is escaped to prevent XSS. To render HTML:

$show->field('body', 'Body')->unescape();

Formatting​

// Custom display
$show->field('avatar')->as(function ($avatar) {
return "<img src='{$avatar}' width='100' />";
})->unescape();

// Image display
$show->field('avatar')->image();

// File download
$show->field('document')->file();

// Link
$show->field('homepage')->link();

// Badge
$show->field('status')->using([
0 => 'Draft',
1 => 'Published',
])->badge();

Panel Customization​

$show->panel()
->style('primary') // primary, info, danger, warning, default
->title('Post Details');

Panel Tools​

$show->panel()->tools(function ($tools) {
$tools->disableEdit();
$tools->disableList();
$tools->disableDelete();
});

Divider​

$show->divider();

Relationships​

One-to-One​

$show->profile('Profile', function ($profile) {
$profile->field('age', 'Age');
$profile->field('address', 'Address');
});

One-to-Many​

$show->comments('Comments', function ($comment) {
$comment->field('id', 'ID');
$comment->field('body', 'Comment');
$comment->field('created_at', 'Posted');
});

Many-to-Many​

$show->tags('Tags', function ($tag) {
$tag->field('name', 'Tag');
});

Conditional Display​

$show->field('secret')->as(function ($value) {
if (Admin::user()->isAdministrator()) {
return $value;
}
return '******';
});