feat: added eligibility check to application save method
This commit addresses an issue where users could submit as many applications as they wanted by simply navigating to the previous page and resubmitting the form, therefore bypassing validation that was only existent in the front end. Fixes #20.
This commit is contained in:
10
app/User.php
10
app/User.php
@@ -121,19 +121,17 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
|
||||
public function isEligible(): bool {
|
||||
$eligible = false;
|
||||
$lastApplication = Application::where('applicantUserID', $this->id)->latest()->first();
|
||||
$lastApplication = Application::where('applicantUserID', $this->getAttribute('id'))->latest()->first();
|
||||
|
||||
if (is_null($lastApplication)) {
|
||||
$eligible = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($lastApplication->created_at->diffInMonths(now()) > 1 && in_array($lastApplication->applicationStatus, ['DENIED', 'APPROVED'])) {
|
||||
|
||||
$eligible = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return $eligible;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user