change keys to values, add test

This commit is contained in:
spencerrlongg 2024-04-30 18:03:26 -05:00
parent 19cff25300
commit 25480293dc
3 changed files with 36 additions and 3 deletions

View file

@ -214,7 +214,7 @@ class BulkAssetsController extends Controller
}
$assets = Asset::whereIn('id', array_keys($request->input('ids')))->get();
$assets = Asset::whereIn('id', $request->input('ids'))->get();

View file

@ -196,8 +196,8 @@
@include("models/custom_fields_form_bulk_edit",["models" => $models])
@foreach ($assets as $key => $value)
<input type="hidden" name="ids[{{ $value }}]" value="1">
@foreach($assets as $asset)
<input type="hidden" name="ids[]" value="{{ $asset }}">
@endforeach
</div> <!--/.box-body-->

View file

@ -0,0 +1,33 @@
<?php
namespace Tests\Feature\Assets;
use App\Models\Asset;
use App\Models\User;
use Carbon\Carbon;
use Tests\TestCase;
class AssetsBulkEditTest extends TestCase
{
public function testBulkEditAsset()
{
$assets = Asset::factory()->count(10)->create(['purchase_date' => '2023-01-01']);
$id_array = $assets->pluck('id')->toArray();
$response = $this->actingAs(User::factory()->editAssets()->create())->post(route('hardware/bulksave'), [
'ids' => array_values($id_array),
'purchase_date' => '2024-01-01'
])
->assertStatus(302)
->assertSessionHasNoErrors();
Asset::findMany($id_array)->each(function (Asset $asset) {
$this->assertEquals('2024-01-01', $asset->purchase_date->format('Y-m-d'));
});
$this->assertDatabaseHas('assets', [
'purchase_date' => '2024-01-01'
]);
}
}