valdiation fires for asset creation

This commit is contained in:
Godfrey M
2025-05-13 12:17:58 -07:00
parent fcbfbca6d0
commit 7fd93645b3
3 changed files with 16 additions and 2 deletions
@@ -120,9 +120,18 @@ class AssetsController extends Controller
for ($a = 1; $a <= count($asset_tags); $a++) {
$asset = new Asset();
$asset->model()->associate(AssetModel::find($request->input('model_id')));
$model = AssetModel::find($request->input('model_id'));
$asset->model()->associate($model);
$asset->name = $request->input('name');
//Validate required serial based on model setting
if ($model && $model->require_serial === 1 && empty($serials[$a] ?? null)) {
return redirect()->back()
->withInput()
->withErrors([
"serials.$a" => trans('admin/hardware/form.serial_required'),
]);
}
// Check for a corresponding serial
if (($serials) && (array_key_exists($a, $serials))) {
$asset->serial = $serials[$a];