Skip to content

Commit

Permalink
Merge pull request #15149 from spencerrlongg/bug/check_requiredness
Browse files Browse the repository at this point in the history
Fixed: Requiredness Check Bug
  • Loading branch information
snipe authored Jul 24, 2024
2 parents 57b5b12 + b61ab42 commit 90a2a80
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,13 +914,22 @@ public static function checkIfRequired($class, $field)
$rules = $class::rules();
foreach ($rules as $rule_name => $rule) {
if ($rule_name == $field) {
if (strpos($rule_name, 'required') === false) {
return false;
if (is_array($rule)) {
if (in_array('required', $rule)) {
$required = true;
} else {
$required = false;
}
} else {
return true;
}
if (strpos($rule, 'required') === false) {
$required = false;
} else {
$required = true;
}
}
}
}
return $required;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Feature/Assets/Ui/EditAssetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Feature\Assets\Ui;

use App\Models\Asset;
use App\Models\User;
use Tests\TestCase;

class EditAssetTest extends TestCase
{
public function testPageCanBeAccessed(): void
{
$asset = Asset::factory()->create();
$user = User::factory()->editAssets()->create();
$response = $this->actingAs($user)->get(route('hardware.edit', $asset->id));

$response->assertStatus(200);
}
}

0 comments on commit 90a2a80

Please sign in to comment.