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

perry020's avatar

Laravel Crud(create) How to pass 3 columns to another column in another table

Hey Good Fellas,

i have 2 tables(one 2 one). Parent table = relation table 'id','name',... child table = relation_identity 'id','first_name','middle_name','last_name'

the goal is: When I am creating relation I only want to fill in first_name, middle_name, last_name and the sum of it must automatically pass the all of it to name in parent table, so i will get full name.

I tried this: $persons = Person::create ([ 'name' => implode(',', (array) $request->input('first_name,middle_name,last_name')) ]); it saves only in child table, but parent table @ column 'name' stays empty.

the question is: What must i research/do in my controller, to achieve the goal?

Thank you!

0 likes
5 replies
vincent15000's avatar

If I have understood, you want to save the first_name, middle_name and last_name in one table and the full_name in another table.

I would do this in two steps :

  • 1rst step : save the child table with the different names
  • 2nd step : save the parent table

So 2 create() methods one after the other.

You have also the possibility to create a MySQL view (assuming you are using MySQL), so that the view automically updates when the other table is updated.

1 like
perry020's avatar

@vincent15000 u mean something like this:

			$persons->identity()->create([
       'first_name' => $request->first_name,
       'middle_name' => $request->middle_name,
        'last_name' => $request->last_name
  $persons = Person::create ([ 'name' => implode(',', (array)$request>input('first_name,middle_name,last_name')) ])
						

?

1 like
vincent15000's avatar

@perry020 Can you please update all your posts in order to display the code properly ? It's difficult to read it ;).

perry020's avatar

@vincent15000 I have a fillable named 'name' in the table relations, i have a fillable named 'first_name', 'middle_name', 'last_name' in the table relations_identity Parent is relation Child is relations_identity and it is One to One. I only want to fill columns of the child and that must pass the data in to parent table column 'name'.

1 like

Please or to participate in this conversation.