Categories
php

laravel 一对多

class OctopusRecord extends Model
{
    use SoftDeletes;
    use HasFactory;
    protected $connection = "beiko_mysql";
    protected $table = 'octopus_records';

    //所有字段一定要满足 小写下划线模式
    public function triage_tags()
    {
        return $this->hasMany(OctopusRecordTriageTag::class,"octopus_record_id");
    }

}
$form->tab("分诊信息",function (Form $subform) {
            $subform->hasMany('triage_tags', "分诊标签", function (Form\NestedForm $nestedForm) {
                $nestedForm->hidden('id');
                $nestedForm->select('name', "标签")->options(TriageTag::all()->pluck('name', 'name'));
                //$nestedForm->text('name', "标签");
            });
            //->distinctFields(["name"]);
                //->useTable();
            //->useTab();;
            //$form->multipleSelect('triage_tags', "分诊标签")->options([0=>"无效",1=>"有效"]);
            //->options(TriageTag::all()->pluck('name', 'name'));

            $subform->textarea('conclusion', __('Conclusion'));
        });

Leave a Reply