mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-23 19:59:18 -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 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'));
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
];
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue