Post::extend(function ($model) {
$model->attachOne['image'] = ['System\Models\File'];
});
Event::listen('backend.form.extendFields', function ($widget) {
// Only for the Posts controller
if (!$widget->getController() instanceof \MyGroup\Blog\Controllers\Posts)
return;
// Only for the Post model
if (!$widget->model instanceof \MyGroup\Blog\Models\Post)
return;
// Update content field
$widget->addSecondaryTabFields([
'image' => [
'tab' => '
rainlab.blog::lang.post.tab_manage',
'label' => '
mygroup.blog::lang.post.preview',
'type' => 'fileupload',
'mode' => 'image',
'imageWidth' => 260,
'imageHeight' => 180
]
]);
});