Simple, a task is connected to a project right?
Then you need to pass the project id when creating the task. So my guess is that your Project is null
Summer Sale! All accounts are 50% off this week.
showing me this error,where i am doing wrong , help me out sir? controller
public function store(Project $project)
{
request()->validate(['body' => 'required']);
$project->addTask(request('body'));
return redirect($project->path());
}
test code
public function test_only_the_owner_of_a_project_can_add_a_task()
{
$this->withoutExceptionHandling();
$this->signIn();
$project = Project::factory()->create();
$this->post($project->path() .'/tasks', ['body' => 'Test task'])
->assertStatus(403);
$this->assertDatabaseMissing('tasks', ['body'=> 'Test Task' ]);
}
error
1) Tests\Feature\ProjectTasksTest::test_only_the_owner_of_a_project_can_add_a_task
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'project_id' cannot be null (SQL: insert into `tasks` (`body`, `project_id`, `updated_at`, `created_at`) values (Test task, ?, 2022-12-05 18:32:54, 2022-12-05 18:32:54))
Please or to participate in this conversation.