Support the ongoing development of Laravel.io →
Database Eloquent

So I am new to Laravel but not to LAMP development, I have been doing this since 1999 and I feel that by using a framework there should be a way to accomplish what I am after.

I have defined the relationships in my various models as need be, some are one to many, some are many to many, etc. When I query data, this works flawlessly. However my concern is with updating or inserting data.

I am sure there is a way to insert or update a record and have the necessary entries in the defined relationships also insert or update, I'm not not sure how to go about it. Where and how can I learn more about this?

Last updated 3 years ago.
0

From the official documentation:

$comment = new App\Comment(['message' => 'A new comment.']);

$post = App\Post::find(1);

$post->comments()->save($comment);

OR

$post = App\Post::find(1);

$comment = $post->comments()->create([
    'message' => 'A new comment.',
]);

For other cases and exaples please refer to the link I gave you.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ArthurJGuy arthurjguy Joined 24 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.