samedi 29 juillet 2017

Populating Users table with foreign key constraint onto another table in Laravel 5.4

I added a column account_id with foreign key constraint onto the accounts table to my users table.

For the registration process I now want the email to be first inserted into the accounts table. Then I want to populate the users table with the account_id and all other registration information.

My RegisterController.php looks like this:

   protected function create(array $data)
   {
      $account = Account::create([
            'email' => $data['email'],

        ]);

        return User::create([
//          'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'account_id' => $accounts['id']
        ]);

    }

This gives me the error Class 'App\Http\Controllers\Auth\Account' not found when creating a new user.

I'm new to Laravel and am a bit lost here. Any pointers would be great!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2vaNNjh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire