php - Populating 2 tables from one controller in Laravel 5.1

42

Just looking for confirmation on what the best way to write a row to 2 separate tables is in an MVC framework (specifically Laravel 5.1)

I have a sign up form, which should eventually add a row to my "users" table and my "profiles" table (These tables have a 1 to 1 relationship).

So, by default my AuthController calls my User models "create" function. Is it OK to have the same function also call my Profile model? Something in the long lost "1st year at uni" part of my brain says this shouldn't happen.

Sorry, I don't have access to my actual code at the moment, but this is basically what I'm getting at:

AuthController
{
    function create($data)
    {
        User::create([
            $data STUFF GOING TO PLACES    
        ])

        Profile::create([
            $data STUFF GOING TO PLACES    
        ])
    }
}

EDIT: To clarify, when a user registers for the site, they will create a row in the users table AND the profile table. So each user row will always have 1 corresponding profile row.

People are also looking for solutions to the problem: php - Adding a new route in Zend Framework2

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.