Skip to content

A free open source IT asset/license management system

Fix for custom fields not saving

snipe2daed3c27169
diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php
index 72b767f59d..af30d8e234 100755
--- a/app/Http/Controllers/AssetsController.php
+++ b/app/Http/Controllers/AssetsController.php
@@ -34,6 +34,7 @@ use Redirect;
use Response;
use Slack;
use Str;
+use Illuminate\Http\Request;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\JsonResponse;
use TCPDF;
@@ -225,6 +226,18 @@ class AssetsController extends Controller
}
+ // Update custom fields in the database.
+ // Validation for these fields is handlded through the AssetRequest form request
+ // FIXME: No idea why this is returning a Builder error on db_column_name.
+ // Need to investigate and fix. Using static method for now.
+ $model = AssetModel::find($request->get('model_id'));
+ if($model->fieldset)
+ {
+ foreach($model->fieldset->fields as $field) {
+ $asset->{\App\Models\CustomField::name_to_db_name($field->name)} = e($request->input(\App\Models\CustomField::name_to_db_name($field->name)));
+ }
+ }
+
// Was the asset created?
if ($asset->save()) {
@@ -299,6 +312,7 @@ class AssetsController extends Controller
public function postEdit(AssetRequest $request, $assetId = null)
{
+
// Check if the asset exists
if (!$asset = Asset::find($assetId)) {
// Redirect to the asset management page with error
@@ -365,8 +379,8 @@ class AssetsController extends Controller
$asset->notes = e($request->input('notes'));
$asset->physical = '1';
- // Update the image
- if (Input::has('image')) {
+ // Update the image
+ if (Input::has('image')) {
$image = $request->input('image');
$header = explode(';', $image, 2)[0];
$extension = substr( $header, strpos($header, '/')+1);
@@ -375,17 +389,29 @@ class AssetsController extends Controller
$file_name = str_random(25).".".$extension;
$path = public_path('uploads/assets/'.$file_name);
-
Image::make($image)->resize(500, 500, function ($constraint) {
- $constraint->aspectRatio();
- $constraint->upsize();
+ $constraint->aspectRatio();
+ $constraint->upsize();
})->save($path);
$asset->image = $file_name;
}
+ // Update custom fields in the database.
+ // Validation for these fields is handlded through the AssetRequest form request
+ // FIXME: No idea why this is returning a Builder error on db_column_name.
+ // Need to investigate and fix. Using static method for now.
+ $model = AssetModel::find($request->get('model_id'));
+ if($model->fieldset)
+ {
+ foreach($model->fieldset->fields as $field) {
+ $asset->{\App\Models\CustomField::name_to_db_name($field->name)} = e($request->input(\App\Models\CustomField::name_to_db_name($field->name)));
+// LOG::debug($field->name);
+// LOG::debug(\App\Models\CustomField::name_to_db_name($field->name));
+// LOG::debug($field->db_column_name());
+ }
+ }
- // Was the asset updated?
if ($asset->save()) {
// Redirect to the new asset page
\Session::flash('success', trans('admin/hardware/message.update.success'));
diff --git a/app/Http/Requests/AssetRequest.php b/app/Http/Requests/AssetRequest.php
index 0e0c0c6416..24b25f2c4a 100644
--- a/app/Http/Requests/AssetRequest.php
+++ b/app/Http/Requests/AssetRequest.php
@@ -31,10 +31,11 @@ class AssetRequest extends Request
'company_id' => 'integer',
'warranty_months' => 'integer|min:0|max:240',
'physical' => 'integer',
- 'checkout_date' => 'date|max:10|min:10',
- 'checkin_date' => 'date|max:10|min:10',
+ 'checkout_date' => 'date',
+ 'checkin_date' => 'date',
'supplier_id' => 'integer',
'status' => 'integer',
+ 'asset_tag' => 'required',
];
$model = AssetModel::find($this->request->get('model_id'));
@@ -45,7 +46,6 @@ class AssetRequest extends Request
}
-
return $rules;
}
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index 9cf7b262a3..4b0c0f3dc1 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -50,7 +50,7 @@ class Asset extends Depreciable
'checkout_date' => 'date|max:10|min:10',
'checkin_date' => 'date|max:10|min:10',
'supplier_id' => 'integer',
- 'asset_tag' => 'required|min:2|max:255|unique:assets,asset_tag,NULL,deleted_at',
+ 'asset_tag' => 'required|min:1|max:255|unique:assets,asset_tag,NULL,deleted_at',
'status' => 'integer',
];
diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php
index 9b429755dd..f6652dd9a1 100755
--- a/resources/views/hardware/edit.blade.php
+++ b/resources/views/hardware/edit.blade.php
@@ -511,11 +511,14 @@ $(function () {
dataType: 'json',
success: function(data) {
// AssetController flashes success to session, redirect to hardware page.
- window.location.href = data.redirect_url;
+ window.location.href = data.redirect_url;
+ // console.dir(data);
+ // console.log('submit was successful');
},
error: function(data) {
// AssetRequest Validator will flash all errors to session, this just refreshes to see them.
window.location.reload(true);
+ // console.log('error submitting');
}
});