File tree Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ public function edit(Request $request) : View | RedirectResponse
163163 $ modelNames = [];
164164
165165 foreach ($ models as $ model ) {
166- $ modelNames [] = $ model ->model ->name ;
166+ $ modelNames [] = $ model ->model ? ->name;
167167 }
168168
169169 if ($ request ->filled ('bulk_actions ' )) {
@@ -470,7 +470,7 @@ public function update(Request $request) : RedirectResponse
470470 */
471471
472472 // Does the model have a fieldset?
473- if ($ asset ->model ->fieldset ) {
473+ if ($ asset ->model ? ->fieldset) {
474474 foreach ($ asset ->model ->fieldset ->fields as $ field ) {
475475
476476 // null custom fields
Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ public function saving(Asset $asset)
175175
176176 // determine if explicit and set eol_explicit to true
177177 if (!is_null ($ asset ->asset_eol_date ) && !is_null ($ asset ->purchase_date )) {
178- if ($ asset ->model ->eol > 0 ) {
178+ if ($ asset ->model ? ->eol > 0 ) {
179179 $ months = (int ) Carbon::parse ($ asset ->asset_eol_date )->diffInMonths ($ asset ->purchase_date , true );
180180 if ($ months != $ asset ->model ->eol ) {
181181 $ asset ->eol_explicit = true ;
@@ -184,7 +184,7 @@ public function saving(Asset $asset)
184184 } elseif (!is_null ($ asset ->asset_eol_date ) && is_null ($ asset ->purchase_date )) {
185185 $ asset ->eol_explicit = true ;
186186 }
187- if ((!is_null ($ asset ->asset_eol_date )) && (!is_null ($ asset ->purchase_date )) && (is_null ($ asset ->model ->eol ) || ($ asset ->model ->eol == 0 ))) {
187+ if ((!is_null ($ asset ->asset_eol_date )) && (!is_null ($ asset ->purchase_date )) && (is_null ($ asset ->model ? ->eol) || ($ asset ->model ? ->eol == 0 ))) {
188188 $ asset ->eol_explicit = true ;
189189 }
190190
Original file line number Diff line number Diff line change 55@endphp
66
77@foreach ($models as $model )
8- @if ($model -> fieldset ? $model -> fieldset -> count () > 0 : false )
8+ @if (( $model ) && ( $model -> fieldset ? $model -> fieldset -> count () > 0 : false ) )
99 @php
1010 $anyModelHasCustomFields ++ ;
1111 @endphp
Original file line number Diff line number Diff line change @@ -29,6 +29,25 @@ public function testUserWithPermissionsCanAccessPage()
2929 ])->assertStatus (200 );
3030 }
3131
32+ public function test_handles_model_being_deleted ()
33+ {
34+ $ this ->withoutExceptionHandling ();
35+
36+ $ user = User::factory ()->viewAssets ()->editAssets ()->create ();
37+ $ assets = Asset::factory ()->count (2 )->create ();
38+
39+ $ assets ->first ()->model ->forceDelete ();
40+
41+ $ id_array = $ assets ->pluck ('id ' )->toArray ();
42+
43+ $ this ->actingAs ($ user )->post ('/hardware/bulkedit ' , [
44+ 'ids ' => $ id_array ,
45+ 'order ' => 'asc ' ,
46+ 'bulk_actions ' => 'edit ' ,
47+ 'sort ' => 'id '
48+ ])->assertStatus (200 );
49+ }
50+
3251 public function test_standard_user_cannot_access_page ()
3352 {
3453 $ user = User::factory ()->create ();
You can’t perform that action at this time.
0 commit comments