diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 158f318133..51892e4259 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -93,6 +93,54 @@ class BulkAssetsController extends Controller $assets = Asset::with('assignedTo', 'location', 'model')->whereIn('assets.id', $asset_ids); + $assets = $assets->get(); + + $models = $assets->unique('model_id'); + $modelNames = []; + foreach($models as $model) { + $modelNames[] = $model->model->name; + } + + if ($request->filled('bulk_actions')) { + + + switch ($request->input('bulk_actions')) { + case 'labels': + $this->authorize('view', Asset::class); + + return (new Label) + ->with('assets', $assets) + ->with('settings', Setting::getSettings()) + ->with('bulkedit', true) + ->with('count', 0); + + case 'delete': + $this->authorize('delete', Asset::class); + $assets->each(function ($assets) { + $this->authorize('delete', $assets); + }); + + return view('hardware/bulk-delete')->with('assets', $assets); + + case 'restore': + $this->authorize('update', Asset::class); + $assets = Asset::withTrashed()->find($asset_ids); + $assets->each(function ($asset) { + $this->authorize('delete', $asset); + }); + return view('hardware/bulk-restore')->with('assets', $assets); + + case 'edit': + $this->authorize('update', Asset::class); + + return view('hardware/bulk') + ->with('assets', $asset_ids) + ->with('statuslabel_list', Helper::statusLabelList()) + ->with('models', $models->pluck(['model'])) + ->with('modelNames', $modelNames); + } + } + switch ($sort_override) { case 'model': $assets->OrderModels($order); @@ -128,54 +176,6 @@ class BulkAssetsController extends Controller break; } - $assets = $assets->get(); - - $models = $assets->unique('model_id'); - $modelNames = []; - foreach($models as $model) { - $modelNames[] = $model->model->name; - } - - if ($request->filled('bulk_actions')) { - - - switch ($request->input('bulk_actions')) { - case 'labels': - $this->authorize('view', Asset::class); - - return (new Label) - ->with('assets', $assets) - ->with('settings', Setting::getSettings()) - ->with('bulkedit', true) - ->with('count', 0); - - case 'delete': - $this->authorize('delete', Asset::class); - $assets->each(function ($assets) { - $this->authorize('delete', $assets); - }); - - return view('hardware/bulk-delete')->with('assets', $assets); - - case 'restore': - $this->authorize('update', Asset::class); - $assets = Asset::withTrashed()->find($asset_ids); - $assets->each(function ($asset) { - $this->authorize('delete', $asset); - }); - return view('hardware/bulk-restore')->with('assets', $assets); - - case 'edit': - $this->authorize('update', Asset::class); - - return view('hardware/bulk') - ->with('assets', $asset_ids) - ->with('statuslabel_list', Helper::statusLabelList()) - ->with('models', $models->pluck(['model'])) - ->with('modelNames', $modelNames); - } - } - return redirect()->back()->with('error', 'No action selected'); }