Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

app/Rules/MaxYearsExperienceRule.php

Open in GitHub
use App\Types\Rule;
use App\Models\Tool;
 
class MaxYearsExperienceRule extends Rule
{
public function message() : string
{
return 'The tool has not existed for that long.';
}
 
public function passes($attribute, $value) : bool
{
$max = Tool::query()
->where('id', $this->parameters[0])
->value('originated');
 
$age = (now()->year - $max) === 0 ? 1 : now()->year - $max;
 
return $value <= $age;
}
}

app/Requests/Requirement/StoreRequest.php

Open in GitHub
use App\Types\FormRequest;
use Illuminate\Validation\Rule;
use App\Rules\MaxYearsExperienceRule;
 
class StoreRequest extends FormRequest
{
public function authorize() : bool
{
$payload = [
Requirement::class,
organization(),
$this->route('vacancy'),
];
 
return user()->can('store', $payload);
}
 
public function rules() : array
{
$unique = Rule::unique('requirements')
->where('vacancy_id', $this->route('vacancy')->id);
 
$years = MaxYearsExperienceRule::make($this->tool_id);
 
return [
'tool_id' => ['bail', 'required', 'uuid', 'exists:tools,id', $unique],
'years' => ['bail', 'required', 'integer', 'min:1', $years],
'optional' => 'bail|required|boolean',
'summary' => 'bail|nullable|string|max:200',
];
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.