diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index 2c49f78bfb..1d64da98e2 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -118,7 +118,7 @@ class AssetCheckinController extends Controller $settings = \App\Models\Setting::getSettings(); - if($settings->require_checkinout_notes=="1" && (is_null($request->note))) { + if($settings->require_checkinout_notes && (is_null($request->note))) { return redirect()->to("hardware/$assetId/checkin")->with('error', trans('admin/hardware/message.update.no_note')); } diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index 9e7a17a942..a73e85db52 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -102,7 +102,7 @@ class AssetCheckoutController extends Controller $settings = \App\Models\Setting::getSettings(); - if($settings->require_checkinout_notes=="1" && (is_null($request->note))) { + if($settings->require_checkinout_notes= && (is_null($request->note))) { return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.update.no_note')); } diff --git a/app/Http/Requests/AssetCheckinRequest.php b/app/Http/Requests/AssetCheckinRequest.php index ea28471899..59ab1a72ec 100644 --- a/app/Http/Requests/AssetCheckinRequest.php +++ b/app/Http/Requests/AssetCheckinRequest.php @@ -14,6 +14,21 @@ class AssetCheckinRequest extends Request return true; } + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + $rules = []; + + if($this->settings->require_checkinout_notes) { + $rules['notes'] = 'required|string'; + } + return $rules; + } + public function response(array $errors) { return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag); diff --git a/app/Models/Setting.php b/app/Models/Setting.php index d775be81c5..1888844508 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -99,6 +99,7 @@ class Setting extends Model protected $casts = [ 'label2_asset_logo' => 'boolean', + 'require_checkinout_notes' => 'boolean', ]; /**