Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Requiredness Check Bug #15149

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading