Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CreateCompanyRequest | |
0.00% |
0 / 47 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| authorize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| rules | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests; |
| 4 | |
| 5 | use Illuminate\Foundation\Http\FormRequest; |
| 6 | |
| 7 | class CreateCompanyRequest extends FormRequest |
| 8 | { |
| 9 | /** |
| 10 | * Determine if the user is authorized to make this request. |
| 11 | */ |
| 12 | public function authorize(): bool |
| 13 | { |
| 14 | return true; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Get the validation rules that apply to the request. |
| 19 | * |
| 20 | * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
| 21 | */ |
| 22 | public function rules(): array |
| 23 | { |
| 24 | $request = $this; |
| 25 | |
| 26 | return [ |
| 27 | 'company.company_name' => 'required|string|max:255|unique:companies,name', |
| 28 | 'company.company_address_line1' => 'required|string', |
| 29 | 'company.company_address_line2' => 'nullable|string', |
| 30 | 'company.city' => 'nullable|string|max:255', |
| 31 | 'company.state' => 'nullable|string|max:255', |
| 32 | 'company.country' => 'required|string|max:255', |
| 33 | 'company.zip_code' => 'nullable|string|max:20', |
| 34 | 'company.term_of_contract' => 'required|integer|min:0', |
| 35 | 'company.custom_term_of_contract' => 'required_if:term_of_contract,0|nullable|integer|min:1', |
| 36 | 'company.contract_start_date' => 'required|date_format:m/d/y', |
| 37 | 'company.contract_end_date' => [ |
| 38 | 'required', |
| 39 | 'regex:/^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/(\d{2}|\d{4})$/', |
| 40 | 'after_or_equal:contract_start_date' |
| 41 | ], |
| 42 | 'company.business_pro_enterprise_plus' => ['required', 'array', 'min:1', function ($attribute, $value, $fail) { |
| 43 | if (in_array('no', $value) && (in_array('yes_dedicated', $value) || in_array('yes_community', $value))) { |
| 44 | $fail('You cannot select "No" along with any "Yes" options.'); |
| 45 | } |
| 46 | }], |
| 47 | 'company.business_pro_enterprise_plus.*' => 'required|string|in:no,yes_dedicated,yes_community', |
| 48 | 'company.total_licenses' => [ |
| 49 | 'required', |
| 50 | 'integer', |
| 51 | 'min:0', |
| 52 | function ($attribute, $value, $fail) use ($request) { |
| 53 | $sum = $request->input('company.starter', 0) |
| 54 | + $request->input('company.growth', 0) |
| 55 | + $request->input('company.sales_pro', 0) |
| 56 | + $request->input('company.sales_pro_teams_smb', 0); |
| 57 | if ($value != $sum) { |
| 58 | $fail('The total licenses must equal the sum of starter, growth, sales_pro, and sales_pro_teams_smb licenses.'); |
| 59 | } |
| 60 | } |
| 61 | ], |
| 62 | 'company.starter' => 'integer|min:0', |
| 63 | 'company.growth' => 'integer|min:0', |
| 64 | 'company.sales_pro' => 'integer|min:0', |
| 65 | 'company.sales_pro_teams_smb' => 'integer|min:0', |
| 66 | 'company.auto_renewal' => 'boolean', |
| 67 | |
| 68 | 'pocs' => 'required|array|min:1', |
| 69 | 'pocs.*.email' => 'required|email|unique:admin_user_invitations|max:255', |
| 70 | 'pocs.*.first_name' => 'required|string|max:255', |
| 71 | 'pocs.*.last_name' => 'required|string|max:255', |
| 72 | 'pocs.*.plan_id' => 'required|string|exists:plans,id', |
| 73 | ]; |
| 74 | } |
| 75 | } |