<?php

namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class DeviceName extends BaseModel
{
    use SoftDeletes;
    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' => '']));
//        }
//        dd($names);
        $names = InnerDeviceNamesModel::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));
    }
}
