Invoke a validator, redirect to edit screen if invalid
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
cb852fc20f
commit
5086c80658
3 changed files with 30 additions and 2 deletions
|
@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use \Illuminate\Contracts\View\View;
|
use \Illuminate\Contracts\View\View;
|
||||||
use \Illuminate\Http\RedirectResponse;
|
use \Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
class AssetCheckinController extends Controller
|
class AssetCheckinController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -40,6 +41,15 @@ class AssetCheckinController extends Controller
|
||||||
if (!$asset->model) {
|
if (!$asset->model) {
|
||||||
return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix'));
|
return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate custom fields on existing asset
|
||||||
|
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return redirect()->route('hardware.edit', $asset)
|
||||||
|
->withErrors($validator);
|
||||||
|
}
|
||||||
|
|
||||||
$target_option = match ($asset->assigned_type) {
|
$target_option = match ($asset->assigned_type) {
|
||||||
'App\Models\Asset' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.asset_previous')]),
|
'App\Models\Asset' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.asset_previous')]),
|
||||||
'App\Models\Location' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.location')]),
|
'App\Models\Location' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.location')]),
|
||||||
|
|
|
@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use \Illuminate\Contracts\View\View;
|
use \Illuminate\Contracts\View\View;
|
||||||
use \Illuminate\Http\RedirectResponse;
|
use \Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
class AssetCheckoutController extends Controller
|
class AssetCheckoutController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -36,6 +37,14 @@ class AssetCheckoutController extends Controller
|
||||||
->with('error', trans('admin/hardware/general.model_invalid_fix'));
|
->with('error', trans('admin/hardware/general.model_invalid_fix'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate custom fields on existing asset
|
||||||
|
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return redirect()->route('hardware.edit', $asset)
|
||||||
|
->withErrors($validator);
|
||||||
|
}
|
||||||
|
|
||||||
if ($asset->availableForCheckout()) {
|
if ($asset->availableForCheckout()) {
|
||||||
return view('hardware/checkout', compact('asset'))
|
return view('hardware/checkout', compact('asset'))
|
||||||
->with('statusLabel_list', Helper::deployableStatusLabelList())
|
->with('statusLabel_list', Helper::deployableStatusLabelList())
|
||||||
|
|
|
@ -877,10 +877,19 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function audit(Asset $asset)
|
public function audit(Asset $asset): View | RedirectResponse
|
||||||
{
|
{
|
||||||
$settings = Setting::getSettings();
|
|
||||||
$this->authorize('audit', Asset::class);
|
$this->authorize('audit', Asset::class);
|
||||||
|
$settings = Setting::getSettings();
|
||||||
|
|
||||||
|
// Validate custom fields on existing asset
|
||||||
|
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return redirect()->route('hardware.edit', $asset)
|
||||||
|
->withErrors($validator);
|
||||||
|
}
|
||||||
|
|
||||||
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
||||||
return view('hardware/audit')->with('asset', $asset)->with('item', $asset)->with('next_audit_date', $dt)->with('locations_list');
|
return view('hardware/audit')->with('asset', $asset)->with('item', $asset)->with('next_audit_date', $dt)->with('locations_list');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue