diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index e5446477cf..27f6044d03 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -163,7 +163,7 @@ class BulkAssetsController extends Controller $modelNames = []; foreach($models as $model) { - $modelNames[] = $model->model->name; + $modelNames[] = $model->model?->name; } if ($request->filled('bulk_actions')) { @@ -470,7 +470,7 @@ class BulkAssetsController extends Controller */ // Does the model have a fieldset? - if ($asset->model->fieldset) { + if ($asset->model?->fieldset) { foreach ($asset->model->fieldset->fields as $field) { // null custom fields diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index d680c6f198..15f1f6ba52 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -5,7 +5,7 @@ @endphp @foreach($models as $model) - @if ($model->fieldset ? $model->fieldset->count() > 0 : false) + @if (($model) && ($model->fieldset ? $model->fieldset->count() > 0 : false)) @php $anyModelHasCustomFields++; @endphp diff --git a/tests/Feature/Assets/Ui/BulkEditAssetsTest.php b/tests/Feature/Assets/Ui/BulkEditAssetsTest.php index 36bb9346b0..04880d4f3c 100644 --- a/tests/Feature/Assets/Ui/BulkEditAssetsTest.php +++ b/tests/Feature/Assets/Ui/BulkEditAssetsTest.php @@ -29,6 +29,25 @@ class BulkEditAssetsTest extends TestCase ])->assertStatus(200); } + public function test_handles_model_being_deleted() + { + $this->withoutExceptionHandling(); + + $user = User::factory()->viewAssets()->editAssets()->create(); + $assets = Asset::factory()->count(2)->create(); + + $assets->first()->model->forceDelete(); + + $id_array = $assets->pluck('id')->toArray(); + + $this->actingAs($user)->post('/hardware/bulkedit', [ + 'ids' => $id_array, + 'order' => 'asc', + 'bulk_actions' => 'edit', + 'sort' => 'id' + ])->assertStatus(200); + } + public function test_standard_user_cannot_access_page() { $user = User::factory()->create();