jeudi 2 avril 2015

Form::Model eloquent binding

I'm having problems populating values of my inputs when I have eloquent queries using with(


Controller:



private $viewPath = "pages.person.";

public function edit($id)
{
$person = Person::where('id', '=', $id)->with('Email', 'Phone', 'User', 'Client', 'JuridicPerson.TypeActivities')->firstOrFail();

$this->setData('person', $person); // Set information to be used in the creation of `views` and `nest.views`.
$this->setData('users', User::lists('name', 'id'), ['0' => 'Select…']); // Set information to be used in the creation of `views` and `nest.views`.

return $this->view($this->viewPath.'edit'); // Register a new view.
}


My views are made in a way that I share the form between my edit and my create. So I have create.blade.php, edit.blade.php and both made a call to form.blade.php this I can not change.


My edit.blade



{{ Form::model($person, array('method' => 'PATCH', 'class' => 'defaultForm', 'route' => array('person.update', $person->id))) }}
@include('pages.person.form')
{{ Form::close() }}


My form.blade



<!-- This input brings the correct value -->
<div class="row">
<div class="col-md-12">
{{ Form::input('name', 'name', null, ['class' => 'form-control', 'placeholder' => 'Nome', 'maxlength' => 35, 'required', 'autofocus']) }}
</div>
</div>
<!-- This input value is empty -->
<div class="row">
<div class="col-md-12">
{{ Form::textarea('Client[observation]', null, ['class' => 'form-control', 'placeholder' => 'Observations']) }}
</div>
</div>


But if I add this piece of code anywhere in my html, I get the correct value in client...



{{ $person->client }}


Not sure what should I do to fix my code, the data is correct, when I print the data (above code) the inputs output the correct value (but I can't have the the return printed on the screen for the user).




What I need is to print the correct value into the correct input.


Aucun commentaire:

Enregistrer un commentaire