Skip to content

A free open source IT asset/license management system

Apply pint to Requests directory

snipe93168326da54
diff --git a/app/Http/Requests/AccessoryCheckoutRequest.php b/app/Http/Requests/AccessoryCheckoutRequest.php
index 3b9afbc28c..6db21eae8f 100644
--- a/app/Http/Requests/AccessoryCheckoutRequest.php
+++ b/app/Http/Requests/AccessoryCheckoutRequest.php
@@ -3,11 +3,11 @@
namespace App\Http\Requests;
use App\Models\Accessory;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Gate;
class AccessoryCheckoutRequest extends ImageUploadRequest
{
-
/**
* Determine if the user is authorized to make this request.
*/
@@ -24,9 +24,9 @@ class AccessoryCheckoutRequest extends ImageUploadRequest
$this->diff = ($this->accessory->numRemaining() - $this->checkout_qty);
$this->merge([
'checkout_qty' => $this->checkout_qty ?? 1,
- 'number_remaining_after_checkout' => (int) ($this->accessory->numRemaining() - $this->checkout_qty),
- 'number_currently_remaining' => (int) $this->accessory->numRemaining(),
- 'checkout_difference' => (int) $this->diff,
+ 'number_remaining_after_checkout' => (int) ($this->accessory->numRemaining() - $this->checkout_qty),
+ 'number_currently_remaining' => (int) $this->accessory->numRemaining(),
+ 'checkout_difference' => (int) $this->diff,
]);
\Log::debug('---------------------------------------------');
@@ -37,17 +37,17 @@ class AccessoryCheckoutRequest extends ImageUploadRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return array_merge(
[
- 'assigned_user' => 'required_without_all:assigned_asset,assigned_location',
- 'assigned_asset' => 'required_without_all:assigned_user,assigned_location',
- 'assigned_location' => 'required_without_all:assigned_user,assigned_asset',
-
+ 'assigned_user' => 'required_without_all:assigned_asset,assigned_location',
+ 'assigned_asset' => 'required_without_all:assigned_user,assigned_location',
+ 'assigned_location' => 'required_without_all:assigned_user,assigned_asset',
+
'number_remaining_after_checkout' => [
'min:0',
'required',
@@ -71,6 +71,7 @@ class AccessoryCheckoutRequest extends ImageUploadRequest
'checkout_qty' => $this->checkout_qty,
]),
];
+
return $messages;
}
}
diff --git a/app/Http/Requests/AssetCheckinRequest.php b/app/Http/Requests/AssetCheckinRequest.php
index 8980cea095..f739e20395 100644
--- a/app/Http/Requests/AssetCheckinRequest.php
+++ b/app/Http/Requests/AssetCheckinRequest.php
@@ -2,6 +2,8 @@
namespace App\Http\Requests;
+use App\Models\Setting;
+
class AssetCheckinRequest extends Request
{
/**
@@ -21,13 +23,14 @@ class AssetCheckinRequest extends Request
*/
public function rules()
{
- $settings = \App\Models\Setting::getSettings();
+ $settings = Setting::getSettings();
$rules = [];
- if($settings->require_checkinout_notes) {
+ if ($settings->require_checkinout_notes) {
$rules['note'] = 'string|required';
}
+
return $rules;
}
diff --git a/app/Http/Requests/AssetCheckoutRequest.php b/app/Http/Requests/AssetCheckoutRequest.php
index 004813c118..31e14b50ad 100644
--- a/app/Http/Requests/AssetCheckoutRequest.php
+++ b/app/Http/Requests/AssetCheckoutRequest.php
@@ -2,6 +2,8 @@
namespace App\Http\Requests;
+use App\Models\Setting;
+
class AssetCheckoutRequest extends Request
{
/**
@@ -21,27 +23,27 @@ class AssetCheckoutRequest extends Request
*/
public function rules()
{
- $settings = \App\Models\Setting::getSettings();
+ $settings = Setting::getSettings();
$rules = [
'assigned_user' => 'numeric|nullable|required_without_all:assigned_asset,assigned_location',
'assigned_asset' => 'numeric|nullable|required_without_all:assigned_user,assigned_location',
'assigned_location' => 'numeric|nullable|required_without_all:assigned_user,assigned_asset',
- 'status_id' => 'exists:status_labels,id,deployable,1',
- 'checkout_to_type' => 'required|in:asset,location,user',
+ 'status_id' => 'exists:status_labels,id,deployable,1',
+ 'checkout_to_type' => 'required|in:asset,location,user',
'checkout_at' => [
'nullable',
'date',
],
'expected_checkin' => [
'nullable',
- 'date'
+ 'date',
],
- ];
+ ];
- if($settings->require_checkinout_notes) {
- $rules['note'] = 'required|string';
- }
+ if ($settings->require_checkinout_notes) {
+ $rules['note'] = 'required|string';
+ }
return $rules;
}
diff --git a/app/Http/Requests/CreateMultipleAssetRequest.php b/app/Http/Requests/CreateMultipleAssetRequest.php
index 0cdd2d24b7..a33cf36b41 100644
--- a/app/Http/Requests/CreateMultipleAssetRequest.php
+++ b/app/Http/Requests/CreateMultipleAssetRequest.php
@@ -4,14 +4,13 @@ namespace App\Http\Requests;
use App\Http\Requests\Traits\MayContainCustomFields;
use App\Models\Asset;
-use Illuminate\Foundation\Http\FormRequest;
-use App\Helpers\Helper;
-use App\Models\Setting;
use App\Models\AssetModel;
+use App\Models\Setting;
use App\Rules\UniqueUndeleted;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;
-class CreateMultipleAssetRequest extends ImageUploadRequest //should I extend from StoreAssetRequest? FIXME OR TODO OR THINKME
+class CreateMultipleAssetRequest extends ImageUploadRequest // should I extend from StoreAssetRequest? FIXME OR TODO OR THINKME
{
use MayContainCustomFields;
@@ -20,17 +19,17 @@ class CreateMultipleAssetRequest extends ImageUploadRequest //should I extend fr
*/
public function authorize(): bool
{
- return true; //TODO - should I do the auth check here?
+ return true; // TODO - should I do the auth check here?
}
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
- //grab the rules for serials and asset_tags, and tweak them into an array context for multi-create usage
+ // grab the rules for serials and asset_tags, and tweak them into an array context for multi-create usage
$modelRules = (new Asset)->getRules();
unset($modelRules['serial']);
@@ -50,7 +49,7 @@ class CreateMultipleAssetRequest extends ImageUploadRequest //should I extend fr
$serial_rules = ['string'];
if ($serials_unique) {
-// $serial_rules[] = 'unique_undeleted:assets,serial';
+ // $serial_rules[] = 'unique_undeleted:assets,serial';
$serial_rules[] = new UniqueUndeleted('assets', 'serial');
$serial_rules[] = 'distinct';
}
diff --git a/app/Http/Requests/CustomAssetReportRequest.php b/app/Http/Requests/CustomAssetReportRequest.php
index 074db091a5..8cf28d2dd5 100644
--- a/app/Http/Requests/CustomAssetReportRequest.php
+++ b/app/Http/Requests/CustomAssetReportRequest.php
@@ -14,15 +14,13 @@ class CustomAssetReportRequest extends Request
return true;
}
-
public function prepareForValidation()
{
- if($this->filled('purchase_cost_end') && !$this->filled('purchase_cost_start')){
- $this->merge(['purchase_cost_start' => 0 ]);
+ if ($this->filled('purchase_cost_end') && ! $this->filled('purchase_cost_start')) {
+ $this->merge(['purchase_cost_start' => 0]);
}
}
-
/**
* Get the validation rules that apply to the request.
*
@@ -31,21 +29,21 @@ class CustomAssetReportRequest extends Request
public function rules()
{
return [
- 'purchase_start' => 'date|date_format:Y-m-d|nullable',
- 'purchase_end' => 'date|date_format:Y-m-d|nullable',
- 'purchase_cost_end' => 'numeric|nullable|gte:purchase_cost_start',
- 'created_start' => 'date|date_format:Y-m-d|nullable',
- 'created_end' => 'date|date_format:Y-m-d|nullable',
- 'checkout_date_start' => 'date|date_format:Y-m-d|nullable',
- 'checkout_date_end' => 'date|date_format:Y-m-d|nullable',
- 'expected_checkin_start' => 'date|date_format:Y-m-d|nullable',
- 'expected_checkin_end' => 'date|date_format:Y-m-d|nullable',
- 'checkin_date_start' => 'date|date_format:Y-m-d|nullable',
- 'checkin_date_end' => 'date|date_format:Y-m-d|nullable',
- 'last_audit_start' => 'date|date_format:Y-m-d|nullable',
- 'last_audit_end' => 'date|date_format:Y-m-d|nullable',
- 'next_audit_start' => 'date|date_format:Y-m-d|nullable',
- 'next_audit_end' => 'date|date_format:Y-m-d|nullable',
+ 'purchase_start' => 'date|date_format:Y-m-d|nullable',
+ 'purchase_end' => 'date|date_format:Y-m-d|nullable',
+ 'purchase_cost_end' => 'numeric|nullable|gte:purchase_cost_start',
+ 'created_start' => 'date|date_format:Y-m-d|nullable',
+ 'created_end' => 'date|date_format:Y-m-d|nullable',
+ 'checkout_date_start' => 'date|date_format:Y-m-d|nullable',
+ 'checkout_date_end' => 'date|date_format:Y-m-d|nullable',
+ 'expected_checkin_start' => 'date|date_format:Y-m-d|nullable',
+ 'expected_checkin_end' => 'date|date_format:Y-m-d|nullable',
+ 'checkin_date_start' => 'date|date_format:Y-m-d|nullable',
+ 'checkin_date_end' => 'date|date_format:Y-m-d|nullable',
+ 'last_audit_start' => 'date|date_format:Y-m-d|nullable',
+ 'last_audit_end' => 'date|date_format:Y-m-d|nullable',
+ 'next_audit_start' => 'date|date_format:Y-m-d|nullable',
+ 'next_audit_end' => 'date|date_format:Y-m-d|nullable',
];
}
diff --git a/app/Http/Requests/CustomFieldRequest.php b/app/Http/Requests/CustomFieldRequest.php
index 0c2ec0ae60..4adb51b0f7 100644
--- a/app/Http/Requests/CustomFieldRequest.php
+++ b/app/Http/Requests/CustomFieldRequest.php
@@ -32,29 +32,27 @@ class CustomFieldRequest extends FormRequest
// Brand new
case 'POST':
- {
+
$rules['name'] = 'required|unique:custom_fields';
break;
- }
- // Save all fields
+ // Save all fields
case 'PUT':
$rules['name'] = 'required';
break;
- // Save only what's passed
+ // Save only what's passed
case 'PATCH':
- {
+
$rules['name'] = 'required';
break;
- }
default:break;
}
$rules['custom_format'] = 'valid_regex';
- return $rules;
+ return $rules;
}
public function messages()
diff --git a/app/Http/Requests/DeleteUserRequest.php b/app/Http/Requests/DeleteUserRequest.php
index 6d387917c6..54800db418 100644
--- a/app/Http/Requests/DeleteUserRequest.php
+++ b/app/Http/Requests/DeleteUserRequest.php
@@ -2,16 +2,14 @@
namespace App\Http\Requests;
-use Illuminate\Foundation\Http\FormRequest;
-use Illuminate\Validation\Rule;
-use Illuminate\Support\Facades\Auth;
use App\Models\User;
+use Illuminate\Contracts\Validation\ValidationRule;
+use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
-
+use Illuminate\Validation\Rule;
class DeleteUserRequest extends FormRequest
{
-
protected $redirectRoute = 'users.index';
/**
@@ -43,13 +41,13 @@ class DeleteUserRequest extends FormRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
- 'user' => Rule::notIn([auth()->id()]),
- 'managed_users' => Rule::in([0]),
+ 'user' => Rule::notIn([auth()->id()]),
+ 'managed_users' => Rule::in([0]),
'managed_locations' => Rule::in([0]),
'assigned_assets' => Rule::in([0]),
'assigned_licenses' => Rule::in([0]),
@@ -80,7 +78,6 @@ class DeleteUserRequest extends FormRequest
// managed locations is not 0
'managed_locations.in' => trans_choice('admin/users/message.error.delete_has_locations_var', $user_to_delete->managedLocations()->count(), ['count' => $user_to_delete->managedLocations()->count()]),
-
// assigned_assets is not 0
'assigned_assets.in' => trans_choice('admin/users/message.error.delete_has_assets_var', $user_to_delete->assets()->count(), ['count' => $user_to_delete->assets()->count()]),
diff --git a/app/Http/Requests/FilterRequest.php b/app/Http/Requests/FilterRequest.php
index d22e58b089..37f5037c6f 100644
--- a/app/Http/Requests/FilterRequest.php
+++ b/app/Http/Requests/FilterRequest.php
@@ -3,6 +3,7 @@
namespace App\Http\Requests;
use App\Rules\ValidJson;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class FilterRequest extends FormRequest
@@ -18,12 +19,12 @@ class FilterRequest extends FormRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
- 'filter' => ['nullable', new ValidJson()],
+ 'filter' => ['nullable', new ValidJson],
];
}
}
diff --git a/app/Http/Requests/ImageUploadRequest.php b/app/Http/Requests/ImageUploadRequest.php
index 3a62212e36..188f8fb304 100644
--- a/app/Http/Requests/ImageUploadRequest.php
+++ b/app/Http/Requests/ImageUploadRequest.php
@@ -2,16 +2,16 @@
namespace App\Http\Requests;
+use App\Http\Traits\ConvertsBase64ToFiles;
use App\Models\SnipeModel;
use enshrined\svgSanitize\Sanitizer;
-use Intervention\Image\Facades\Image;
-use App\Http\Traits\ConvertsBase64ToFiles;
use Illuminate\Http\UploadedFile;
-use Illuminate\Support\Facades\Storage;
-use Intervention\Image\Exception\NotReadableException;
use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
-use Illuminate\Support\Str;
+use Illuminate\Validation\ValidationException;
+use Intervention\Image\Exception\NotReadableException;
+use Intervention\Image\Facades\Image;
class ImageUploadRequest extends Request
{
@@ -34,20 +34,20 @@ class ImageUploadRequest extends Request
*/
public function rules()
{
-
- return [
- 'image' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp,avif',
- 'avatar' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp,avif',
- 'favicon' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp,image/x-icon,image/vnd.microsoft.icon,ico',
- ];
+
+ return [
+ 'image' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp,avif',
+ 'avatar' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp,avif',
+ 'favicon' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp,image/x-icon,image/vnd.microsoft.icon,ico',
+ ];
}
public function response(array $errors)
{
return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag);
}
-
- /**
+
+ /**
* Fields that should be traited from base64 to files
*/
protected function base64FileKeys(): array
@@ -55,18 +55,19 @@ class ImageUploadRequest extends Request
/**
* image_source is here just legacy reasons. Api\AssetController
* had it once to allow encoded image uploads.
- */
+ */
return [
'image' => 'auto',
- 'image_source' => 'auto'
+ 'image_source' => 'auto',
];
}
/**
* Handle and store any images attached to request
- * @param SnipeModel $item Item the image is associated with
- * @param string $path location for uploaded images, defaults to uploads/plural of item type.
- * @return SnipeModel Target asset is being checked out to.
+ *
+ * @param SnipeModel $item Item the image is associated with
+ * @param string $path location for uploaded images, defaults to uploads/plural of item type.
+ * @return SnipeModel Target asset is being checked out to.
*/
public function handleImages($item, $w = 600, $form_fieldname = 'image', $path = null, $db_fieldname = 'image')
{
@@ -87,67 +88,63 @@ class ImageUploadRequest extends Request
}
-
- if (!Storage::disk('public')->exists($path)) {
+ if (! Storage::disk('public')->exists($path)) {
Storage::disk('public')->makeDirectory($path);
}
if ($this->offsetGet($form_fieldname) instanceof UploadedFile) {
- $image = $this->offsetGet($form_fieldname);
+ $image = $this->offsetGet($form_fieldname);
} elseif ($this->hasFile($form_fieldname)) {
$image = $this->file($form_fieldname);
}
if (isset($image)) {
+ $ext = $image->guessExtension();
+ $file_name = $type.'-'.$form_fieldname.($item->id ?? '-'.$item->id).'-'.str_random(10).'.'.$ext;
- $ext = $image->guessExtension();
- $file_name = $type.'-'.$form_fieldname.($item->id ?? '-'.$item->id).'-'.str_random(10).'.'.$ext;
-
- if (($image->getMimeType() == 'image/vnd.microsoft.icon') || ($image->getMimeType() == 'image/x-icon') || ($image->getMimeType() == 'image/avif') || ($image->getMimeType() == 'image/webp')) {
- // If the file is an icon, webp or avif, we need to just move it since gd doesn't support resizing
- // icons or avif, and webp support and needs to be compiled into gd for resizing to be available
- Storage::disk('public')->put($path.'/'.$file_name, file_get_contents($image));
-
- } elseif($image->getMimeType() == 'image/svg+xml') {
- // If the file is an SVG, we need to clean it and NOT encode it
- $sanitizer = new Sanitizer();
- $dirtySVG = file_get_contents($image->getRealPath());
- $cleanSVG = $sanitizer->sanitize($dirtySVG);
-
- try {
- Storage::disk('public')->put($path . '/' . $file_name, $cleanSVG);
- } catch (\Exception $e) {
- Log::debug($e);
- }
- } else {
-
- try {
- $upload = Image::make($image->getRealPath())->setFileInfoFromPath($image->getRealPath())->resize(null, $w, function ($constraint) {
- $constraint->aspectRatio();
- $constraint->upsize();
- })->orientate();
-
- } catch(NotReadableException $e) {
- Log::debug($e);
- $validator = Validator::make([], []);
- $validator->errors()->add($form_fieldname, trans('general.unaccepted_image_type', ['mimetype' => $image->getClientMimeType()]));
-
- throw new \Illuminate\Validation\ValidationException($validator);
- }
-
- // This requires a string instead of an object, so we use ($string)
- Storage::disk('public')->put($path.'/'.$file_name, (string) $upload->encode());
+ if (($image->getMimeType() == 'image/vnd.microsoft.icon') || ($image->getMimeType() == 'image/x-icon') || ($image->getMimeType() == 'image/avif') || ($image->getMimeType() == 'image/webp')) {
+ // If the file is an icon, webp or avif, we need to just move it since gd doesn't support resizing
+ // icons or avif, and webp support and needs to be compiled into gd for resizing to be available
+ Storage::disk('public')->put($path.'/'.$file_name, file_get_contents($image));
+ } elseif ($image->getMimeType() == 'image/svg+xml') {
+ // If the file is an SVG, we need to clean it and NOT encode it
+ $sanitizer = new Sanitizer;
+ $dirtySVG = file_get_contents($image->getRealPath());
+ $cleanSVG = $sanitizer->sanitize($dirtySVG);
+
+ try {
+ Storage::disk('public')->put($path.'/'.$file_name, $cleanSVG);
+ } catch (\Exception $e) {
+ Log::debug($e);
}
+ } else {
+
+ try {
+ $upload = Image::make($image->getRealPath())->setFileInfoFromPath($image->getRealPath())->resize(null, $w, function ($constraint) {
+ $constraint->aspectRatio();
+ $constraint->upsize();
+ })->orientate();
- // Remove Current image if exists
- $item = $this->deleteExistingImage($item, $path, $db_fieldname);
- $item->{$db_fieldname} = $file_name;
+ } catch (NotReadableException $e) {
+ Log::debug($e);
+ $validator = Validator::make([], []);
+ $validator->errors()->add($form_fieldname, trans('general.unaccepted_image_type', ['mimetype' => $image->getClientMimeType()]));
+ throw new ValidationException($validator);
+ }
+ // This requires a string instead of an object, so we use ($string)
+ Storage::disk('public')->put($path.'/'.$file_name, (string) $upload->encode());
- // If the user isn't uploading anything new but wants to delete their old image, do so
+ }
+
+ // Remove Current image if exists
+ $item = $this->deleteExistingImage($item, $path, $db_fieldname);
+ $item->{$db_fieldname} = $file_name;
+
+ // If the user isn't uploading anything new but wants to delete their old image, do so
} elseif ($this->input('image_delete') == '1') {
$item = $this->deleteExistingImage($item, $path, $db_fieldname);
}
@@ -155,9 +152,10 @@ class ImageUploadRequest extends Request
return $item;
}
- public function deleteExistingImage($item, $path = null, $db_fieldname = 'image') {
+ public function deleteExistingImage($item, $path = null, $db_fieldname = 'image')
+ {
- if ($item->{$db_fieldname}!='') {
+ if ($item->{$db_fieldname} != '') {
try {
Storage::disk('public')->delete($path.'/'.$item->{$db_fieldname});
$item->{$db_fieldname} = null;
@@ -168,5 +166,4 @@ class ImageUploadRequest extends Request
return $item;
}
-
}
diff --git a/app/Http/Requests/ItemImportRequest.php b/app/Http/Requests/ItemImportRequest.php
index a32f5c32b3..d8c53949ee 100644
--- a/app/Http/Requests/ItemImportRequest.php
+++ b/app/Http/Requests/ItemImportRequest.php
@@ -4,7 +4,6 @@ namespace App\Http\Requests;
use App\Models\Import;
use Illuminate\Foundation\Http\FormRequest;
-use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class ItemImportRequest extends FormRequest
@@ -33,7 +32,7 @@ class ItemImportRequest extends FormRequest
public function import(Import $import)
{
- ini_set('max_execution_time', env('IMPORT_TIME_LIMIT', 600)); //600 seconds = 10 minutes
+ ini_set('max_execution_time', env('IMPORT_TIME_LIMIT', 600)); // 600 seconds = 10 minutes
ini_set('memory_limit', env('IMPORT_MEMORY_LIMIT', '500M'));
$filename = config('app.private_uploads').'/imports/'.$import->file_path;
@@ -61,11 +60,11 @@ class ItemImportRequest extends FormRequest
$fieldMappings = array_change_key_case(array_flip($import->field_map), CASE_LOWER);
}
$importer->setCallbacks([$this, 'log'], [$this, 'progress'], [$this, 'errorCallback'])
- ->setCreatedBy(auth()->id())
- ->setUpdating($this->input('import-update'))
- ->setShouldNotify($this->input('send-welcome'))
- ->setUsernameFormat('firstname.lastname')
- ->setFieldMappings($fieldMappings);
+ ->setCreatedBy(auth()->id())
+ ->setUpdating($this->input('import-update'))
+ ->setShouldNotify($this->input('send-welcome'))
+ ->setUsernameFormat('firstname.lastname')
+ ->setFieldMappings($fieldMappings);
$importer->import();
return $this->errors;
diff --git a/app/Http/Requests/LicenseCheckoutRequest.php b/app/Http/Requests/LicenseCheckoutRequest.php
index a40c91653e..ad14e00e1c 100644
--- a/app/Http/Requests/LicenseCheckoutRequest.php
+++ b/app/Http/Requests/LicenseCheckoutRequest.php
@@ -24,8 +24,8 @@ class LicenseCheckoutRequest extends FormRequest
public function rules()
{
return [
- 'note' => 'string|nullable',
- 'asset_id' => 'required_without:assigned_to',
+ 'note' => 'string|nullable',
+ 'asset_id' => 'required_without:assigned_to',
];
}
}
diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php
index e4562e275d..03e671549f 100644
--- a/app/Http/Requests/Request.php
+++ b/app/Http/Requests/Request.php
@@ -14,6 +14,7 @@ abstract class Request extends FormRequest
if ($this->ajax() || $this->wantsJson()) {
json_decode($this->getContent(), false, 512, JSON_THROW_ON_ERROR); // ignore output, just throw
}
+
return parent::json($key, $default);
}
diff --git a/app/Http/Requests/SaveUserRequest.php b/app/Http/Requests/SaveUserRequest.php
index b5ee656a9d..bdc0d0d69f 100644
--- a/app/Http/Requests/SaveUserRequest.php
+++ b/app/Http/Requests/SaveUserRequest.php
@@ -3,10 +3,8 @@
namespace App\Http\Requests;
use App\Models\Setting;
-use Illuminate\Contracts\Validation\Validator;
-use Illuminate\Foundation\Http\FormRequest;
-use Illuminate\Http\Exceptions\HttpResponseException;
use App\Rules\UserCannotSwitchCompaniesIfItemsAssigned;
+use Illuminate\Foundation\Http\FormRequest;
class SaveUserRequest extends FormRequest
{
@@ -35,7 +33,7 @@ class SaveUserRequest extends FormRequest
$rules = [
'department_id' => 'nullable|integer|exists:departments,id',
'manager_id' => 'nullable|integer|exists:users,id',
- 'company_id' => ['nullable', 'integer', 'exists:companies,id']
+ 'company_id' => ['nullable', 'integer', 'exists:companies,id'],
];
switch ($this->method()) {
@@ -49,18 +47,18 @@ class SaveUserRequest extends FormRequest
}
break;
- // Save all fields
+ // Save all fields
case 'PUT':
$rules['first_name'] = 'required|string|min:1';
$rules['username'] = 'required_unless:ldap_import,1|string|min:1';
$rules['password'] = Setting::passwordComplexityRulesSaving('update').'|confirmed';
- $rules['company_id'] = [new UserCannotSwitchCompaniesIfItemsAssigned()];
+ $rules['company_id'] = [new UserCannotSwitchCompaniesIfItemsAssigned];
break;
- // Save only what's passed
+ // Save only what's passed
case 'PATCH':
$rules['password'] = Setting::passwordComplexityRulesSaving('update');
- $rules['company_id'] = [new UserCannotSwitchCompaniesIfItemsAssigned()];
+ $rules['company_id'] = [new UserCannotSwitchCompaniesIfItemsAssigned];
break;
default:
diff --git a/app/Http/Requests/SettingsLdapRequest.php b/app/Http/Requests/SettingsLdapRequest.php
index 75eb15f230..d89cb3733a 100644
--- a/app/Http/Requests/SettingsLdapRequest.php
+++ b/app/Http/Requests/SettingsLdapRequest.php
@@ -3,6 +3,8 @@
namespace App\Http\Requests;
use Illuminate\Support\Facades\Session;
+use Illuminate\Support\MessageBag;
+use Illuminate\Support\ViewErrorBag;
class SettingsLdapRequest extends Request
{
@@ -24,16 +26,16 @@ class SettingsLdapRequest extends Request
public function rules()
{
$rules = [
- 'ldap_server' => 'sometimes|required_if:ldap_enabled,1|url|nullable',
- 'ldap_uname' => 'sometimes|required_if:ldap_enabled,1|nullable',
- 'ldap_basedn' => 'sometimes|required_if:ldap_enabled,1|nullable',
- 'ldap_filter' => 'sometimes|required_if:ldap_enabled,1|nullable',
- 'ldap_username_field' => 'sometimes|required_if:ldap_enabled,1|nullable',
- 'ldap_fname_field' => 'sometimes|required_if:ldap_enabled,1|nullable',
- 'ldap_lname_field' => 'sometimes|required_if:ldap_enabled,1|nullable',
- 'ldap_auth_filter_query' => 'sometimes|required_if:ldap_enabled,1|nullable',
- 'ldap_version' => 'sometimes|required_if:ldap_enabled,1|nullable',
- 'ad_domain' => 'sometimes|required_if:is_ad,1|nullable',
+ 'ldap_server' => 'sometimes|required_if:ldap_enabled,1|url|nullable',
+ 'ldap_uname' => 'sometimes|required_if:ldap_enabled,1|nullable',
+ 'ldap_basedn' => 'sometimes|required_if:ldap_enabled,1|nullable',
+ 'ldap_filter' => 'sometimes|required_if:ldap_enabled,1|nullable',
+ 'ldap_username_field' => 'sometimes|required_if:ldap_enabled,1|nullable',
+ 'ldap_fname_field' => 'sometimes|required_if:ldap_enabled,1|nullable',
+ 'ldap_lname_field' => 'sometimes|required_if:ldap_enabled,1|nullable',
+ 'ldap_auth_filter_query' => 'sometimes|required_if:ldap_enabled,1|nullable',
+ 'ldap_version' => 'sometimes|required_if:ldap_enabled,1|nullable',
+ 'ad_domain' => 'sometimes|required_if:is_ad,1|nullable',
];
return $rules;
@@ -41,8 +43,8 @@ class SettingsLdapRequest extends Request
public function response(array $errors)
{
- $this->session()->flash('errors', Session::get('errors', new \Illuminate\Support\ViewErrorBag)
- ->put('default', new \Illuminate\Support\MessageBag($errors)));
+ $this->session()->flash('errors', Session::get('errors', new ViewErrorBag)
+ ->put('default', new MessageBag($errors)));
\Input::flash();
return parent::response($errors);
diff --git a/app/Http/Requests/SettingsSamlRequest.php b/app/Http/Requests/SettingsSamlRequest.php
index c9d91d2ba0..7552369cd2 100644
--- a/app/Http/Requests/SettingsSamlRequest.php
+++ b/app/Http/Requests/SettingsSamlRequest.php
@@ -5,7 +5,6 @@ namespace App\Http\Requests;
use App\Models\Setting;
use Illuminate\Foundation\Http\FormRequest;
use OneLogin\Saml2\IdPMetadataParser as OneLogin_Saml2_IdPMetadataParser;
-use OneLogin\Saml2\Utils as OneLogin_Saml2_Utils;
/**
* This handles validating and cleaning SAML settings provided by the user.
@@ -81,7 +80,7 @@ class SettingsSamlRequest extends FormRequest
} elseif ($split[0] == 'sp_privateKey') {
$custom_privateKey = $split[1];
} elseif ($split[0] == 'sp_x509certNew') {
- //to prepare for Key rollover
+ // to prepare for Key rollover
$custom_x509certNew = $split[1];
}
}
@@ -127,10 +126,10 @@ class SettingsSamlRequest extends FormRequest
}
if (! (empty($x509cert) && empty($privateKey))) {
-// $this->merge([
-// 'saml_sp_x509cert' => $x509cert,
-// 'saml_sp_privatekey' => $privateKey,
-// ]);
+ // $this->merge([
+ // 'saml_sp_x509cert' => $x509cert,
+ // 'saml_sp_privatekey' => $privateKey,
+ // ]);
$setting->saml_sp_x509cert = $x509cert;
$setting->saml_sp_privatekey = $privateKey;
$setting->save();
@@ -150,21 +149,20 @@ class SettingsSamlRequest extends FormRequest
}
if (! empty($x509certNew)) {
-// $this->merge([
-// 'saml_sp_x509certNew' => $x509certNew,
-// ]);
+ // $this->merge([
+ // 'saml_sp_x509certNew' => $x509certNew,
+ // ]);
$setting->saml_sp_x509certNew = $x509certNew;
$setting->save();
}
} else {
-// $this->merge([
-// 'saml_sp_x509certNew' => '',
-// ]);
+ // $this->merge([
+ // 'saml_sp_x509certNew' => '',
+ // ]);
$setting->saml_sp_x509certNew = '';
$setting->save();
}
-
});
}
}
diff --git a/app/Http/Requests/SetupUserRequest.php b/app/Http/Requests/SetupUserRequest.php
index 7de61f939a..5b2f1d6f80 100644
--- a/app/Http/Requests/SetupUserRequest.php
+++ b/app/Http/Requests/SetupUserRequest.php
@@ -22,12 +22,12 @@ class SetupUserRequest extends Request
public function rules()
{
return [
- 'site_name' => 'required|string|min:1',
- 'first_name' => 'required|string|min:1',
- 'last_name' => 'required|string|min:1',
- 'username' => 'required|string|min:2|unique:users,username,NULL,deleted_at',
- 'email' => 'email|unique:users,email',
- 'password' => 'required|min:8|confirmed',
+ 'site_name' => 'required|string|min:1',
+ 'first_name' => 'required|string|min:1',
+ 'last_name' => 'required|string|min:1',
+ 'username' => 'required|string|min:2|unique:users,username,NULL,deleted_at',
+ 'email' => 'email|unique:users,email',
+ 'password' => 'required|min:8|confirmed',
];
}
diff --git a/app/Http/Requests/StoreAccessoryRequest.php b/app/Http/Requests/StoreAccessoryRequest.php
index a06420b135..afa2bf3e15 100644
--- a/app/Http/Requests/StoreAccessoryRequest.php
+++ b/app/Http/Requests/StoreAccessoryRequest.php
@@ -4,11 +4,11 @@ namespace App\Http\Requests;
use App\Models\Accessory;
use App\Models\Category;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Gate;
class StoreAccessoryRequest extends ImageUploadRequest
{
-
/**
* Determine if the user is authorized to make this request.
*/
@@ -34,7 +34,7 @@ class StoreAccessoryRequest extends ImageUploadRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
@@ -47,6 +47,7 @@ class StoreAccessoryRequest extends ImageUploadRequest
public function messages(): array
{
$messages = ['category_type.in' => trans('admin/accessories/message.invalid_category_type')];
+
return $messages;
}
diff --git a/app/Http/Requests/StoreAssetModelRequest.php b/app/Http/Requests/StoreAssetModelRequest.php
index fa450a072e..bfe7eb8308 100644
--- a/app/Http/Requests/StoreAssetModelRequest.php
+++ b/app/Http/Requests/StoreAssetModelRequest.php
@@ -4,11 +4,11 @@ namespace App\Http\Requests;
use App\Models\AssetModel;
use App\Models\Category;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Gate;
class StoreAssetModelRequest extends ImageUploadRequest
{
-
/**
* Determine if the user is authorized to make this request.
*/
@@ -34,7 +34,7 @@ class StoreAssetModelRequest extends ImageUploadRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
@@ -47,6 +47,7 @@ class StoreAssetModelRequest extends ImageUploadRequest
public function messages(): array
{
$messages = ['category_type.in' => trans('admin/models/message.invalid_category_type')];
+
return $messages;
}
diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php
index 5460ef6e5e..6ff8d51eb9 100644
--- a/app/Http/Requests/StoreAssetRequest.php
+++ b/app/Http/Requests/StoreAssetRequest.php
@@ -6,18 +6,17 @@ use App\Http\Requests\Traits\MayContainCustomFields;
use App\Models\Asset;
use App\Models\Company;
use App\Models\Setting;
+use App\Rules\AssetCannotBeCheckedOutToNondeployableStatus;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;
use Illuminate\Support\Facades\Gate;
-use App\Rules\AssetCannotBeCheckedOutToNondeployableStatus;
class StoreAssetRequest extends ImageUploadRequest
{
use MayContainCustomFields;
+
/**
* Determine if the user is authorized to make this request.
- *
- * @return bool
*/
public function authorize(): bool
{
@@ -45,8 +44,6 @@ class StoreAssetRequest extends ImageUploadRequest
/**
* Get the validation rules that apply to the request.
- *
- * @return array
*/
public function rules(): array
{
@@ -63,7 +60,7 @@ class StoreAssetRequest extends ImageUploadRequest
return array_merge(
$modelRules,
- ['status_id' => [new AssetCannotBeCheckedOutToNondeployableStatus()]],
+ ['status_id' => [new AssetCannotBeCheckedOutToNondeployableStatus]],
parent::rules(),
);
}
diff --git a/app/Http/Requests/StoreConsumableRequest.php b/app/Http/Requests/StoreConsumableRequest.php
index 67ffa51a10..cfe2fccae9 100644
--- a/app/Http/Requests/StoreConsumableRequest.php
+++ b/app/Http/Requests/StoreConsumableRequest.php
@@ -2,13 +2,13 @@
namespace App\Http\Requests;
-use App\Models\Consumable;
use App\Models\Category;
+use App\Models\Consumable;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Gate;
class StoreConsumableRequest extends ImageUploadRequest
{
-
/**
* Determine if the user is authorized to make this request.
*/
@@ -34,7 +34,7 @@ class StoreConsumableRequest extends ImageUploadRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
@@ -47,6 +47,7 @@ class StoreConsumableRequest extends ImageUploadRequest
public function messages(): array
{
$messages = ['category_type.in' => trans('admin/consumables/message.invalid_category_type')];
+
return $messages;
}
diff --git a/app/Http/Requests/StoreDepartmentRequest.php b/app/Http/Requests/StoreDepartmentRequest.php
index 5c5f1e61f9..ecccefb30e 100644
--- a/app/Http/Requests/StoreDepartmentRequest.php
+++ b/app/Http/Requests/StoreDepartmentRequest.php
@@ -3,7 +3,7 @@
namespace App\Http\Requests;
use App\Models\Department;
-use Illuminate\Foundation\Http\FormRequest;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Gate;
class StoreDepartmentRequest extends ImageUploadRequest
@@ -19,7 +19,7 @@ class StoreDepartmentRequest extends ImageUploadRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
diff --git a/app/Http/Requests/StoreLabelSettings.php b/app/Http/Requests/StoreLabelSettings.php
index 1f0e2a03ee..900db6a755 100644
--- a/app/Http/Requests/StoreLabelSettings.php
+++ b/app/Http/Requests/StoreLabelSettings.php
@@ -2,8 +2,8 @@
namespace App\Http\Requests;
-
use App\Models\Labels\Label;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rule;
@@ -21,7 +21,7 @@ class StoreLabelSettings extends FormRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
@@ -36,21 +36,21 @@ class StoreLabelSettings extends FormRequest
}
return [
- 'labels_per_page' => 'numeric',
- 'labels_width' => 'numeric|min:0.1',
- 'labels_height' => 'numeric|min:0.1',
- 'labels_pmargin_left' => 'numeric|nullable',
- 'labels_pmargin_right' => 'numeric|nullable',
- 'labels_pmargin_top' => 'numeric|nullable',
- 'labels_pmargin_bottom' => 'numeric|nullable',
- 'labels_display_bgutter' => 'numeric|nullable',
- 'labels_display_sgutter' => 'numeric|nullable',
- 'labels_fontsize' => 'numeric|min:5',
- 'labels_pagewidth' => 'numeric|nullable',
- 'labels_pageheight' => 'numeric|nullable',
- 'qr_text' => 'max:31|nullable',
- 'label2_2d_prefix' => 'nullable|max:191',
- 'label2_template' => [
+ 'labels_per_page' => 'numeric',
+ 'labels_width' => 'numeric|min:0.1',
+ 'labels_height' => 'numeric|min:0.1',
+ 'labels_pmargin_left' => 'numeric|nullable',
+ 'labels_pmargin_right' => 'numeric|nullable',
+ 'labels_pmargin_top' => 'numeric|nullable',
+ 'labels_pmargin_bottom' => 'numeric|nullable',
+ 'labels_display_bgutter' => 'numeric|nullable',
+ 'labels_display_sgutter' => 'numeric|nullable',
+ 'labels_fontsize' => 'numeric|min:5',
+ 'labels_pagewidth' => 'numeric|nullable',
+ 'labels_pageheight' => 'numeric|nullable',
+ 'qr_text' => 'max:31|nullable',
+ 'label2_2d_prefix' => 'nullable|max:191',
+ 'label2_template' => [
'required',
Rule::in($names),
],
diff --git a/app/Http/Requests/StoreLdapSettings.php b/app/Http/Requests/StoreLdapSettings.php
index ce0fa41bf5..f58150e167 100644
--- a/app/Http/Requests/StoreLdapSettings.php
+++ b/app/Http/Requests/StoreLdapSettings.php
@@ -2,6 +2,7 @@
namespace App\Http\Requests;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
@@ -18,7 +19,7 @@ class StoreLdapSettings extends FormRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
@@ -32,5 +33,4 @@ class StoreLdapSettings extends FormRequest
'custom_forgot_pass_url' => 'nullable|url',
];
}
-
}
diff --git a/app/Http/Requests/StoreLocalizationSettings.php b/app/Http/Requests/StoreLocalizationSettings.php
index 4cea8826e8..c68b3f397b 100644
--- a/app/Http/Requests/StoreLocalizationSettings.php
+++ b/app/Http/Requests/StoreLocalizationSettings.php
@@ -2,6 +2,7 @@
namespace App\Http\Requests;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
@@ -18,13 +19,13 @@ class StoreLocalizationSettings extends FormRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
- 'default_currency' => 'required',
- 'locale' => 'required',
+ 'default_currency' => 'required',
+ 'locale' => 'required',
];
}
}
diff --git a/app/Http/Requests/StoreNotificationSettings.php b/app/Http/Requests/StoreNotificationSettings.php
index 34d8d44715..0dd32342c7 100644
--- a/app/Http/Requests/StoreNotificationSettings.php
+++ b/app/Http/Requests/StoreNotificationSettings.php
@@ -2,7 +2,7 @@
namespace App\Http\Requests;
-use App\Models\Accessory;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rule;
@@ -20,22 +20,21 @@ class StoreNotificationSettings extends FormRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
- 'alert_email' => 'email_array|nullable',
- 'admin_cc_email' => 'email_array|nullable',
+ 'alert_email' => 'email_array|nullable',
+ 'admin_cc_email' => 'email_array|nullable',
'admin_cc_always' => [
Rule::in('0', '1'),
],
- 'alert_threshold' => 'numeric|nullable',
- 'alert_interval' => 'numeric|nullable|gt:0',
- 'audit_warning_days' => 'numeric|nullable|gte:0',
- 'due_checkin_days' => 'numeric|nullable|gt:0',
- 'audit_interval' => 'numeric|nullable|gt:0',
+ 'alert_threshold' => 'numeric|nullable',
+ 'alert_interval' => 'numeric|nullable|gt:0',
+ 'audit_warning_days' => 'numeric|nullable|gte:0',
+ 'due_checkin_days' => 'numeric|nullable|gt:0',
+ 'audit_interval' => 'numeric|nullable|gt:0',
];
}
-
}
diff --git a/app/Http/Requests/StoreSecuritySettings.php b/app/Http/Requests/StoreSecuritySettings.php
index 42a529aa57..31e237e658 100644
--- a/app/Http/Requests/StoreSecuritySettings.php
+++ b/app/Http/Requests/StoreSecuritySettings.php
@@ -2,6 +2,7 @@
namespace App\Http\Requests;
+use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
@@ -18,18 +19,18 @@ class StoreSecuritySettings extends FormRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+ * @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
- 'pwd_secure_min' => 'numeric|required|min:8',
- 'custom_forgot_pass_url' => 'url|nullable',
- 'privacy_policy_link' => 'nullable|url',
- 'login_remote_user_enabled' => 'numeric|nullable',
- 'login_common_disabled' => 'numeric|nullable',
+ 'pwd_secure_min' => 'numeric|required|min:8',
+ 'custom_forgot_pass_url' => 'url|nullable',
+ 'privacy_policy_link' => 'nullable|url',
+ 'login_remote_user_enabled' => 'numeric|nullable',
+ 'login_common_disabled' => 'numeric|nullable',
'login_remote_user_custom_logout_url' => 'string|nullable',
- 'login_remote_user_header_name' => 'string|nullable',
+ 'login_remote_user_header_name' => 'string|nullable',
];
}
}
diff --git a/app/Http/Requests/Traits/MayContainCustomFields.php b/app/Http/Requests/Traits/MayContainCustomFields.php
index 2b12ccff6e..2014e10d74 100644
--- a/app/Http/Requests/Traits/MayContainCustomFields.php
+++ b/app/Http/Requests/Traits/MayContainCustomFields.php
@@ -12,11 +12,11 @@ trait MayContainCustomFields
{
// In case the model is being changed via form
- if (request()->has('model_id')!='') {
+ if (request()->has('model_id') != '') {
$asset_model = AssetModel::find(request()->input('model_id'));
- // or if we have it available to route-model-binding
+ // or if we have it available to route-model-binding
} elseif ((request()->route('asset') && (request()->route('asset')->model_id))) {
$asset_model = AssetModel::find(request()->route('asset')->model_id);
@@ -32,7 +32,6 @@ trait MayContainCustomFields
}
}
-
// collect the custom fields in the request
$validator->after(function ($validator) use ($asset_model) {
$request_fields = $this->collect()->keys()->filter(function ($attributes) {
@@ -42,15 +41,14 @@ trait MayContainCustomFields
// if there are custom fields, find the ones that don't exist on the model's fieldset and add an error to the validator's error bag
if (count($request_fields) > 0 && $validator->errors()->isEmpty()) {
$request_fields->diff($asset_model?->fieldset?->fields?->pluck('db_column'))
- ->each(function ($request_field_name) use ($request_fields, $validator) {
- if (CustomField::where('db_column', $request_field_name)->exists()) {
- $validator->errors()->add($request_field_name, trans('validation.custom.custom_field_not_found_on_model'));
- } else {
- $validator->errors()->add($request_field_name, trans('validation.custom.custom_field_not_found'));
- }
- });
+ ->each(function ($request_field_name) use ($validator) {
+ if (CustomField::where('db_column', $request_field_name)->exists()) {
+ $validator->errors()->add($request_field_name, trans('validation.custom.custom_field_not_found_on_model'));
+ } else {
+ $validator->errors()->add($request_field_name, trans('validation.custom.custom_field_not_found'));
+ }
+ });
}
});
}
}
-
diff --git a/app/Http/Requests/UpdateAssetRequest.php b/app/Http/Requests/UpdateAssetRequest.php
index 6d01dc5a30..c8f258ed45 100644
--- a/app/Http/Requests/UpdateAssetRequest.php
+++ b/app/Http/Requests/UpdateAssetRequest.php
@@ -11,6 +11,7 @@ use Illuminate\Validation\Rule;
class UpdateAssetRequest extends ImageUploadRequest
{
use MayContainCustomFields;
+
/**
* Determine if the user is authorized to make this request.
*
@@ -37,7 +38,7 @@ class UpdateAssetRequest extends ImageUploadRequest
// Confusingly, this skips the unique_undeleted validator at the model level (and therefore the UniqueUndeletedTrait), so we have to re-add those
// rules here without the requiredness, since those values will already exist if you're updating an existing asset.
[
- 'model_id' => ['integer', 'exists:models,id,deleted_at,NULL', 'not_array'],
+ 'model_id' => ['integer', 'exists:models,id,deleted_at,NULL', 'not_array'],
'status_id' => ['integer', 'exists:status_labels,id'],
'asset_tag' => [
'min:1', 'max:255', 'not_array',
@@ -45,7 +46,7 @@ class UpdateAssetRequest extends ImageUploadRequest
],
'serial' => [
'string', 'max:255', 'not_array',
- $setting->unique_serial=='1' ? Rule::unique('assets', 'serial')->ignore($this->asset)->withoutTrashed() : 'nullable',
+ $setting->unique_serial == '1' ? Rule::unique('assets', 'serial')->ignore($this->asset)->withoutTrashed() : 'nullable',
],
],
);
diff --git a/app/Http/Requests/UploadFileRequest.php b/app/Http/Requests/UploadFileRequest.php
index 82f4a35be1..e647b0307c 100644
--- a/app/Http/Requests/UploadFileRequest.php
+++ b/app/Http/Requests/UploadFileRequest.php
@@ -2,15 +2,16 @@
namespace App\Http\Requests;
+use App\Helpers\Helper;
use App\Http\Traits\ConvertsBase64ToFiles;
use enshrined\svgSanitize\Sanitizer;
-use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Log;
-use \App\Helpers\Helper;
+use Illuminate\Support\Facades\Storage;
class UploadFileRequest extends Request
{
use ConvertsBase64ToFiles;
+
/**
* Determine if the user is authorized to make this request.
*
@@ -63,18 +64,16 @@ class UploadFileRequest extends Request
public function handleSVG($file)
{
- $sanitizer = new Sanitizer();
+ $sanitizer = new Sanitizer;
$dirtySVG = file_get_contents($file->getRealPath());
+
return $sanitizer->sanitize($dirtySVG);
}
-
/**
* Get the validation error messages that apply to the request, but
* replace the attribute name with the name of the file that was attempted and failed
* to make it clearer to the user which file is the bad one.
- *
- * @return array
*/
public function attributes(): array
{
@@ -100,4 +99,4 @@ class UploadFileRequest extends Request
return $attributes;
}
-}
\ No newline at end of file
+}