Sure!
Set up the relationships on the relevant models and use the relationship to automatically set the foreign key.
$user = App\User::create([
//user data
]);
$user->profile()->create([
// user profile data
]);
return // whatever
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello.
I am building a web application which has "users" and "profiles". I set up the relationships in my Models and the database is working OK, no errors or such.
In my logic, a user has ONE profile and a profile has ONE user, so it's a one-to-one relationship. In my profiles table, I have the usual "user_id" column.
Now here's my question.
Can I use my UsersController to automatically create a profile when a user is created, and link that profile to the user (via "user_id" column)?
Thanks!
Please or to participate in this conversation.