mardi 22 janvier 2019

Do a return of multiple create function Laravel

Just finished a php artisan make:auth, In app\Http\Controllers\Auth\RegisterController lies the default create function:

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ]);
}

I have added in the view of the same page of this default view (/register) a birthdate from another model. How do I insert a new create function in the same default create function?

enter image description here

UserInformation::create([
    'user_id' => ???
    'birth_date' => $data['birth_dae']
]);

How can I connect this to the above return statement and how will I able to get the newly created id from the User and pass it to the user_id of UserInformation?

My Idea so far:

protected function create(array $data)
{
    return [
        User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
        ]),
        UserInformation::create([
        'user_id' => ??? // should be the same as the id of the created user
        'birth_date' => $data['birth_date'],
        'color' => "blue"
        ])
    ];
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire