|
@@ -0,0 +1,58 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Http\Requests\API\Requirement;
|
|
|
|
+
|
|
|
|
+use App\Http\Requests\RuleHelper;
|
|
|
|
+use App\Models\Enums\RequirementStatus;
|
|
|
|
+use App\Models\User;
|
|
|
|
+use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
|
+use Illuminate\Validation\Rule;
|
|
|
|
+use Illuminate\Validation\Rules\Enum;
|
|
|
|
+
|
|
|
|
+class CreateOrUpdateRequest extends FormRequest
|
|
|
|
+{
|
|
|
|
+ use RuleHelper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Determine if the user is authorized to make this request.
|
|
|
|
+ */
|
|
|
|
+ public function authorize(): bool
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Get the validation rules that apply to the request.
|
|
|
|
+ *
|
|
|
|
+ * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
|
|
+ */
|
|
|
|
+ public function rules(): array
|
|
|
|
+ {
|
|
|
|
+ return [
|
|
|
|
+ 'title' => 'required|max:255',
|
|
|
|
+ 'status' => [
|
|
|
|
+ 'required',
|
|
|
|
+ new Enum(RequirementStatus::class),
|
|
|
|
+ ],
|
|
|
|
+ 'asset_id' => [
|
|
|
|
+ 'required',
|
|
|
|
+ Rule::exists('assets', 'id')->where($this->userCompanyWhere()),
|
|
|
|
+ ],
|
|
|
|
+ 'mailto' => [
|
|
|
|
+ 'array',
|
|
|
|
+ function ($attribute, $value, $fail) {
|
|
|
|
+ $userCount = User::where("company_id", Auth::user()->company_id)->whereIn('id', $value)->count();
|
|
|
|
+ if ($userCount != count($value)) {
|
|
|
|
+ $fail('The selected user is invalid.');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ 'priority' => 'required|in:1,2,3,4',
|
|
|
|
+ 'requirement_group_id' => [
|
|
|
|
+ 'required',
|
|
|
|
+ Rule::exists('requirement_groups', 'id')->where($this->userCompanyWhere()),
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+}
|