| 123456789101112131415161718192021222324252627 | <?phpnamespace App\Models;class DeviceName extends BaseModel{    public function device()    {        return $this->belongsTo('App\Models\Device', 'device_id');    }    public function getNameSpecOptions()    {        $names = DeviceName::select('name as text', 'id as value')->get();        $names = $names->prepend($this->transObject(['text' => '设备名称', 'value' => '']));        foreach($names as $name) {            $specs  = Spec::where('device_name_id', $name->value)->select('name as text', 'id as value')->get();            $name->specs = $specs->prepend($this->transObject(['text' => '规格型号', 'value' => '']));        }        return $names;    }    public function transObject($items)    {        return json_decode(json_encode($items));    }}
 |