mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Fix for custom fields not saving
This commit is contained in:
parent
c1a3592059
commit
2daed3c271
|
@ -34,6 +34,7 @@ use Redirect;
|
||||||
use Response;
|
use Response;
|
||||||
use Slack;
|
use Slack;
|
||||||
use Str;
|
use Str;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use TCPDF;
|
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?
|
// Was the asset created?
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
|
|
||||||
|
@ -299,6 +312,7 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
public function postEdit(AssetRequest $request, $assetId = null)
|
public function postEdit(AssetRequest $request, $assetId = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Check if the asset exists
|
// Check if the asset exists
|
||||||
if (!$asset = Asset::find($assetId)) {
|
if (!$asset = Asset::find($assetId)) {
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
|
@ -375,7 +389,6 @@ class AssetsController extends Controller
|
||||||
$file_name = str_random(25).".".$extension;
|
$file_name = str_random(25).".".$extension;
|
||||||
$path = public_path('uploads/assets/'.$file_name);
|
$path = public_path('uploads/assets/'.$file_name);
|
||||||
|
|
||||||
|
|
||||||
Image::make($image)->resize(500, 500, function ($constraint) {
|
Image::make($image)->resize(500, 500, function ($constraint) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
$constraint->upsize();
|
$constraint->upsize();
|
||||||
|
@ -383,9 +396,22 @@ class AssetsController extends Controller
|
||||||
$asset->image = $file_name;
|
$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()) {
|
if ($asset->save()) {
|
||||||
// Redirect to the new asset page
|
// Redirect to the new asset page
|
||||||
\Session::flash('success', trans('admin/hardware/message.update.success'));
|
\Session::flash('success', trans('admin/hardware/message.update.success'));
|
||||||
|
|
|
@ -31,10 +31,11 @@ class AssetRequest extends Request
|
||||||
'company_id' => 'integer',
|
'company_id' => 'integer',
|
||||||
'warranty_months' => 'integer|min:0|max:240',
|
'warranty_months' => 'integer|min:0|max:240',
|
||||||
'physical' => 'integer',
|
'physical' => 'integer',
|
||||||
'checkout_date' => 'date|max:10|min:10',
|
'checkout_date' => 'date',
|
||||||
'checkin_date' => 'date|max:10|min:10',
|
'checkin_date' => 'date',
|
||||||
'supplier_id' => 'integer',
|
'supplier_id' => 'integer',
|
||||||
'status' => 'integer',
|
'status' => 'integer',
|
||||||
|
'asset_tag' => 'required',
|
||||||
];
|
];
|
||||||
|
|
||||||
$model = AssetModel::find($this->request->get('model_id'));
|
$model = AssetModel::find($this->request->get('model_id'));
|
||||||
|
@ -45,7 +46,6 @@ class AssetRequest extends Request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Asset extends Depreciable
|
||||||
'checkout_date' => 'date|max:10|min:10',
|
'checkout_date' => 'date|max:10|min:10',
|
||||||
'checkin_date' => 'date|max:10|min:10',
|
'checkin_date' => 'date|max:10|min:10',
|
||||||
'supplier_id' => 'integer',
|
'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',
|
'status' => 'integer',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -512,10 +512,13 @@ $(function () {
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
// AssetController flashes success to session, redirect to hardware page.
|
// 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) {
|
error: function(data) {
|
||||||
// AssetRequest Validator will flash all errors to session, this just refreshes to see them.
|
// AssetRequest Validator will flash all errors to session, this just refreshes to see them.
|
||||||
window.location.reload(true);
|
window.location.reload(true);
|
||||||
|
// console.log('error submitting');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue