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

adnanerlansyah403's avatar

How to create a data that have relationship with a simple way

hello everyone, I have a question or maybe need a suggestions about how to handle creating a data using eloquent and there's a relationship. so for example, I want to created a user and then profile at the same time but I don't want make it like this

$user = User::create([
    email: $request->email
    .......... : $request->....
]);
// And then for profile
Profile::create([
      user_id: $user->id
      ................. : $request->....
]);

So basically I did that for creating data that have a relationship. But is there a the other way for making this like simple? Like afterCreated I want to do something.

Thanks everyone 🙏

0 likes
1 reply

Please or to participate in this conversation.