Skip to content

Commit

Permalink
make some naming a little clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerrlongg committed Jul 9, 2024
1 parent 1a1ccd6 commit 6932a63
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/Http/Controllers/AssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Actionlog;
use App\Models\AssetModel;
use App\Models\CustomField;
use App\Models\SnipeModel;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -457,7 +458,7 @@ private function shouldAddDefaultValues(array $input) : bool
* @param AssetModel $model
* @param array $defaultValues
*/
private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues): bool
private function assignCustomFieldsDefaultValues(AssetModel|SnipeModel $model, array $defaultValues): bool
{
$data = array();
foreach ($defaultValues as $customFieldId => $defaultValue) {
Expand All @@ -466,17 +467,17 @@ private function assignCustomFieldsDefaultValues(AssetModel $model, array $defau
$data[$customField->db_column] = $defaultValue;
}

$fieldsets = $model->fieldset->validation_rules();
$allRules = $model->fieldset->validation_rules();
$rules = array();

foreach ($fieldsets as $fieldset => $validation){
foreach ($allRules as $field => $validation) {
// If the field is marked as required, eliminate the rule so it doesn't interfere with the default values
// (we are at model level, the rule still applies when creating a new asset using this model)
$index = array_search('required', $validation);
if ($index !== false){
$validation[$index] = 'nullable';
}
$rules[$fieldset] = $validation;
$rules[$field] = $validation;
}

$validator = Validator::make($data, $rules);
Expand All @@ -499,7 +500,7 @@ private function assignCustomFieldsDefaultValues(AssetModel $model, array $defau
* Removes all default values
*
*/
private function removeCustomFieldsDefaultValues(AssetModel $model) : void
private function removeCustomFieldsDefaultValues(AssetModel|SnipeModel $model): void
{
$model->defaultValues()->detach();
}
Expand Down

0 comments on commit 6932a63

Please sign in to comment.