php - Laravel form binding with one to one relationships -



php - Laravel form binding with one to one relationships -

i have business relationship model has polymorphic relation address model. set one-to-one releationship set so:

account:

public function address() { homecoming $this->morphone('address', 'hasaddress', 'add_hasaddress_type', 'add_hasaddress_id', 'act_id'); }

address:

public function hasaddress() { homecoming $this->morphto('hasaddress', 'add_hasaddress_type', 'add_hasaddress_id'); }

on form edit account, have address fields. can bind business relationship object plenty doing:

{{ form::model($account, array('route' => array('accounts/edit', $account->act_id), 'method' => 'put')) }} {{ form::label('act_name', 'account name:') }} {{ form::text('act_name', input::old('act_name')) }}

and fills in fields properly. but, how populate address fields? researched, need do:

{{ form::text('address.add_city', input::old('address.add_city')) }}

to access relation's values, doesn't work.

i tried

{{ form::text('address[add_city]', input::old('address[add_city]')) }}

as suggested similar title. both of these tried , without old input. not work poymorphic relations or doing wrong?

also, how handle these forms in controller?

nothing relations in form model binding documentation, , doing search brings people asking one-to-many binding.

it works *-to-one relation (for many-to-many, ie. collection of models won't work):

// prepare model related info - eager loading $account = account::with('address')->find($someid); // or lazy loading $account = account::find($someid); $account->load('address'); // view template {{ form::model($account, ...) }} account: {{ form::text('acc_name') }} city: {{ form::text('address[add_city]') }} {{ form::close() }}

no need input::old or whatsoever, null plenty default value. laravel fill info in order (docs wrong here!):

1. old input 2. bound info 3. value passed helper

mind must load relation (dynamic phone call won't work in case).

another thing processing input later - laravel not automatically hydrate related model, need like:

$accountdata = input::only(['acc_name', ... other business relationship fields]); // or $accountdata = input::except(['address']); // validate etc, then: $account->fill($accountdata); $addressdata = input::get('address'); // validate ofc, then: $account->address->fill($addressdata);

php laravel-4 eloquent

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -