@tykus done this change but when i dd the request here is the result i didn't get the owner_id from factory why?
factory code is on my first question of this forum..
array:2 [ // app\Http\Controllers\ProjectsController.php:22
"title" => "Exercitationem ipsa distinctio aut et."
"description" => "Ab dolorem veniam eum quia et saepe aut."
]
array:2 [ // app\Http\Controllers\ProjectsController.php:22
"title" => "Exercitationem ipsa distinctio aut et."
"description" => "Ab dolorem veniam eum quia et saepe aut."
]
@tykus yea !
telling me that owner_id doesn't have a default value but i am passing null when we create it and also from my factory..why showing error?
SQLSTATE[HY000]: General error: 1364 Field 'owner_id' doesn't have a default value (SQL: insert into `projects` (`title`, `description`, `updated_at`, `created_at`) values (Laudantium quae inventore dolores laudantium nam sunt., Voluptas quo asperiores id magnam., 2022-11-09 22:07:32, 2022-11-09 22:07:32))
my factory code
public function definition()
{
return [
'title' => $this->faker->sentence,
'description' => $this->faker->sentence,
'owner_id' => function () {
return User::factory()->create()->id;
}
];
}
@tykus now it showing that owner_id have not a default value but when i dd it gives me the id
public function test_a_project_requires_an_owner()
{
$attributes = Project::factory()->raw();
// dd($attributes);
$this->post('/projects', $attributes)->assertSessionHasErrors('owner');
}
error
SQLSTATE[HY000]: General error: 1364 Field 'owner_id' doesn't have a default value (SQL: insert into `projects` (`title`, `description`, `updated_at`, `created_at`) values (Impedit iusto molestias saepe id est velit labore., Dolores qui ratione id nobis aliquam repellat., 2022-11-09 22:23:31, 2022-11-09 22:23:31))
@Shivamyadav okay, you don;'t have owner_id in the $attributes array because there is no rule (commented) for it! The validate method returns only the keys from the Request that have a rule: