根据条件显示旧输入

时间:2016-04-19 13:57:22

标签: laravel laravel-5 laravel-5.1

我将文档对象传递给我的视图。如果我执行以下操作,我可以看到对象

{{dd($briefingDoc)}}

现在这个Document有很多DocumentData。如果我在我的视图中执行以下操作

{{dd($projectIdentifiedDoc->documentData->toArray())}}

我得到这样的东西

array:8 [▼
  0 => array:7 [▼
    "id" => 62
    "documentId" => 13
    "key" => "whatData"
    "value" => "some data"
    "deleted_at" => null
    "created_at" => "2016-04-19 12:46:19"
    "updated_at" => "2016-04-19 12:46:19"
  ]
  1 => array:7 [▼
    "id" => 63
    "documentId" => 13
    "key" => "whoData"
    "value" => ""
    "deleted_at" => null
    "created_at" => "2016-04-19 12:46:19"
    "updated_at" => "2016-04-19 12:46:19"
  ]
  2 => array:7 [▼
    "id" => 64
    "documentId" => 13
    "key" => "startDate"
    "value" => "29/04/2016"
    "deleted_at" => null
    "created_at" => "2016-04-19 12:46:19"
    "updated_at" => "2016-04-19 12:46:19"
  ]
  3 => array:7 [▶]
  4 => array:7 [▶]
  5 => array:7 [▶]
  6 => array:7 [▶]
  7 => array:7 [▶]
]

所以我的视图现在有数据,我需要在适当的输入中显示适当的数据。目前我正在尝试这样的事情

{!! Form::textArea('whatData', $projectIdentifiedDoc->documentData->value, array('class' => 'form-control')) !!}

现在显然不会工作。我不知何故需要检查密钥是否与输入标签匹配,如果是,则显示该值。这段代码都错了,但希望如此 它让你知道我在追求什么

{!! Form::textArea('whatData', if($projectIdentifiedDoc->documentData->key == 'whatData'){$projectIdentifiedDoc->documentData->value}, array('class' => 'form-control')) !!}

这样的事情会成为可能吗?

由于

1 个答案:

答案 0 :(得分:1)

尝试where()方法:

$value = $projectIdentifiedDoc->documentData->where('key', 'whatData')->first()->value;

{!! Form::textArea('whatData', $value, array('class' => 'form-control')) !!}