From 9687a78981d56bd01e088b1d0a49da9d5938e0fd Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 28 Oct 2017 15:17:36 -0700 Subject: [PATCH] Fixed a few inconsistencies in the API results (null vs empty string) --- app/Http/Controllers/Api/AssetsController.php | 2 +- app/Http/Transformers/AssetsTransformer.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 642ca8c08a..e61361dcb7 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -256,7 +256,7 @@ class AssetsController extends Controller */ public function show($id) { - if ($asset = Asset::withTrashed()->findOrFail($id)) { + if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()->findOrFail($id)) { $this->authorize('view', $asset); return (new AssetsTransformer)->transformAsset($asset); } diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index dcac0950ae..6170b7b475 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -30,7 +30,7 @@ class AssetsTransformer 'id' => (int) $asset->model->id, 'name'=> e($asset->model->name) ] : null, - 'model_number' => ($asset->model) ? e($asset->model->model_number) : null, + 'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null, 'status_label' => ($asset->assetstatus) ? [ 'id' => (int) $asset->assetstatus->id, 'name'=> e($asset->present()->statusText), @@ -135,8 +135,8 @@ class AssetsTransformer 'username' => e($asset->assigned->username), 'name' => e($asset->assigned->getFullNameAttribute()), 'first_name'=> e($asset->assigned->first_name), - 'last_name'=> e($asset->assigned->last_name), - 'employee_number' => e($asset->assigned->employee_num), + 'last_name'=> ($asset->assigned->last_name) ? e($asset->assigned->last_name) : null, + 'employee_number' => ($asset->assigned->employee_num) ? e($asset->assigned->employee_num) : null, 'type' => 'user' ] : null; }