You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.4 KiB

<?php
namespace App\Forms;
use App\Models\TrainingType;
use Kris\LaravelFormBuilder\Form;
use Kris\LaravelFormBuilder\Field;
class TrainingForm extends Form
{
public function buildForm()
{
$this->add("id", Field::HIDDEN);
$this->add("title", Field::TEXT, ["label" => "名称", "rules" => "required"]);
$this->add("type_id", Field::SELECT, ["label" => "所属分类", "rules" => "required", "choices" => $this->getTypes()]);
$this->add("poster", Field::TEXT, ["label" => "标题图", "rules" => "required", "attr" => [
"data-plugin" => "uploader"
]]);
$this->add("video", Field::TEXT, ["label" => "视频文件", "rules" => "required", "attr" => [
"data-plugin" => "uploader"
]]);
$this->add("published_at", Field::TEXT, ["label" => "发布时间", "default_value" => "", "help_block" => [
"text" => "留空表示未发布"
],"attr"=>[
"data-plugin" => "datetime-picker"
]]);
$this->add('buttons', 'buttongroup', ["splitted" => true, "buttons" => [
["label" => "保存", "attr" => ["class" => "btn btn-primary mr-1", "type" => "submit"]],
["label" => "返回", "attr" => ["class" => "btn btn-light btn-back", "type" => "button"]]
]]);
}
public function getTypes()
{
$types = TrainingType::orderBy("myindex")->pluck("name", "id")->toArray();
return $types;
}
}