I'm trying to create an entry in another table when a new user registers. I put this in my RegisterController
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'dob' => $data['dob'],
]);
Season::create([
'user_id', $user->id,
'module', 0,
'current', 0,
'completed', 0,
]);
return $user;
}
Here's my table migration
public function up()
{
Schema::create('seasons', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->foreignId('user_id')->constrained();
$table->integer('module');
$table->integer('current');
$table->integer('completed');
});
}
I'm using postgres and for some reason it's telling me that my $user->id is passing null. What am I doing wrong here?
Here's the complete error message.
SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "user_id" violates not-null constraint DETAIL: Failing row contains (1, 2020-09-22 18:44:21, 2020-09-22 18:44:21, null, null, null, null). (SQL: insert into "seasons" ("updated_at", "created_at") values (2020-09-22 18:44:21, 2020-09-22 18:44:21) returning "id")