Skip to content

Commit

Permalink
change keys to values, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerrlongg committed Apr 30, 2024
1 parent 19cff25 commit 2548029
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Assets/BulkAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function update(Request $request)
}


$assets = Asset::whereIn('id', array_keys($request->input('ids')))->get();
$assets = Asset::whereIn('id', $request->input('ids'))->get();



Expand Down
4 changes: 2 additions & 2 deletions resources/views/hardware/bulk.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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-->

Expand Down
33 changes: 33 additions & 0 deletions tests/Feature/Assets/AssetsBulkEditTest.php
Original file line number Diff line number Diff line change
@@ -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'
]);
}
}

0 comments on commit 2548029

Please sign in to comment.