I want the data obtained from find table1 to insert into table2
$table1= Table1::find($id);
$table2= new Table2();
without
$table2->field1 = $table1->field1;
$table2->field2 = $table1->field2;
where I have multiple fields
How do I use it? to be able to write short code
3
Answers
mean like this?
if the fields in table2 are same with table1
Laravel has the replicate() function that will do your job.
This is how you can use it:
This function will clone your one model data into another object. If you want to change/add/replace any data from the model data then you can also add/modify it:
I hope that this is what you are looking for. 😄😄
If all the fields are same in both tables, you can try,