Saving a model with multiple foreign keys in Laravel 4 -


i understand in order save foreign key, 1 should use related model , associate() function, worth trouble of going through this

$user = new user([     'name' => input::get('name'),      'email' => input::get('email') ]);  $language = language::find(input::get('language_id'); $gender = gender::find(input::get('gender_id'); $city = city::find(input::get('city_id');  $user->language()->associate($language); $user->gender()->associate($gender); $user->city()->associate($city);  $user->save(); 

when 1 can this?

user::create(input::all()); 

i feel i'm missing here, maybe there's simpler , cleaner way handle foreign keys in controllers (and views)?

you can use push() method instead allow push related models.

this link should answer query. eloquent push() , save() difference


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

angularjs - ng-repeat duplicating items after page reload -