Answer the question
In order to leave comments, you need to log in
How to pass an array with the Post method?
Good afternoon. I am writing a test for a controller,
Controller
public function update(Request $request) {
$input = $request->get('category', []);
foreach (Category::all() as $category) {
$category->roles()->sync(Arr::get($input, $category->id, []));
}
dd($input);
return view('home');
}
/** @test */
public function test_admin_user_can_edit_categories_roles()
{
$category = \App\Models\Category::factory()->create(['id' => 1]);
$role = \App\Models\Role::factory()->create(['id' => 1]);
$data = [
'1' => ['1' => '1'],
'2' => ['1' => '1'],
];
$this->actingAs(\App\Models\User::factory()->create(['role_id' => 1]));
$this->post('/admin/connections', $data);
$this->assertDatabaseHas('categories_roles', [
'categories_id' => $category->id,
'roles_id' => $role->id
]);
}
Answer the question
In order to leave comments, you need to log in
$data = [
'category' => [
'1' => ['1' => '1'],
'2' => ['1' => '1'],
],
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question