Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JoerJoers's avatar

1 Form many input data for different tables.

Basically, i have one form with many inputs for different tables. For example, one form with many inputs for Personal Information [Table 1], Address [Table 1] and Payment Info [Table 1] using the Form Facade for Post method via a Controller [user@create]. My initial solution is to store the data one by one to its equivalent column in the database. Is there any way to make this easier or how should this be handle properly? See sample table below.

Tables:

  1. USER - 5 columns
  2. Address - 3 columns
  3. Payment Info - 5 columns.

One Form and One Controller.

$user = new App\User; $user->first_name = Input::get('first_name'); $user->last_name = Input::get('last_name'); .........

$address = new App\Address; $address->city = Input::get('city'); ...........

$payment = new App\Payment; $payment->account_num = Input::get('acct_num'); ........

0 likes
4 replies
Mo7sin's avatar

Is there any relationships between those tables?

JoerJoers's avatar

Yes there is. For example, User hasOne Address and Payment Info. Is there any way? or the only way is to store it one by one? $user->first_name = Input::get('first_name') and so on.

Mo7sin's avatar
Mo7sin
Best Answer
Level 51

You ca do this

$address = new App\Address(['city' = Input::get('city')]);
$payment = new App\Payment(['account_num' = Input::get('acct_num')]); 

$user = User::create(Input::all());
$user->address()->save($address);
$user->payment()->save($payment);

Please or to participate in this conversation.