In laravel, is there some way of nesting related resources in a form?
Say I have this:
class Person extends Eloquent {
public function addresses() {
return $this->hasMany("Address");
}
}
class Address extends Eloquent {
public function person() {
return $this->belongsTo("Person");
}
}
and I want a Person
form to collect information about that Person
's Address
es. Does laravel facilitate this in a way that is equivalent to Rails' accepts_nested_attributes_for :address
and fields_for :address
?
I'd just like something simple where I can include the Address
fields with the results of the Person
form, since the Address
doesn't really exist apart from the Person
. Does this make sense?
== EDIT ==
This is hypothetical code
What I'm looking for is something that would resemble this:
{{ Form::model(new Person, array("action" => "admin\PersonController@store", "method" => "POST")) }}
{{ Form::text("name", array(...)) // <input name='person[name]' ... /> }}
{{ Form::email("email", array(...)) // <input name='person[email]' ... /> }}
{{ Form::fields_for("addresses"/* Would be name of relation */) }}
{{ Form::text("street_address") // <input name='person[addresses][][street_address]' ... /> }}
{{ Form::close_fields() }}
{{ Form::close() }}
Address::persons
was a typo. Fixed