jeudi 7 janvier 2016

Laravel 5 - retrieving old input

I am passing one of my views a document object. Within my view, if I do

{{ $document }}

I can see the document

{
    "id":2,
    "projectId":1,
    "name":"DocumentA"
} 

This document has data, the form data that was submitted. In my view, if I do

{{ $document->documentData }}

I can see

[
    {
        "id":1,
        "documentId":2,
        "key":"_token",
        "value":"WJGplDnTuMpDK7X3AD9dgIliX2SliBSz2sjxivVy"
    },
    {
        "id":2,
        "documentId":2,
        "key":"teamLeader",
        "value":"Jason Sullivan"
    },
    {
        "id":3,
        "documentId":2,
        "key":"clientName",
        "value":"Google"
    },
    {
        "id":4,
        "documentId":2,
        "key":"projectName",
        "value":"Analytics"
    }
] 

So all of this data is related to DocumentA, linked by documentId.

So my view now has this document object, and I can access the data for the document. The key is the input field, and the value was the inputted data. An input in my view generally looks like the following

{!! Form::label('teamLeader', 'Team Leader:', array('class' => 'col-sm-5 control-label green')) !!}
{!! Form::textArea('teamLeader', old('$document->documentData'), array('class' => 'form-control')) !!}

As you can see, I am trying to get the old data displayed in my edit form. This input is for teamLeader, so it should display the value where teamLeader is the key. So in the data I outputted above, you can see that this field should display Jason Sullivan.

How would I go about getting it to do this?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire