FinancialPlanAccountRequest.php 953 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. class FinancialPlanAccountRequest extends FormRequest
  5. {
  6. public function rules(): array
  7. {
  8. $isCreate = $this->isMethod('POST');
  9. return [
  10. 'code' => [$isCreate ? 'required' : 'sometimes', 'string', 'max:50'],
  11. 'description' => [$isCreate ? 'required' : 'sometimes', 'string', 'max:255'],
  12. // chart_type é obrigatório só quando NÃO há pai; com pai, é herdado.
  13. 'chart_type' => [
  14. $isCreate ? 'required_without:parent_id' : 'sometimes',
  15. 'nullable',
  16. 'string',
  17. 'max:50',
  18. ],
  19. 'parent_id' => ['nullable', 'integer', 'exists:financial_plan_accounts,id'],
  20. 'order' => ['nullable', 'string', 'max:50'],
  21. 'unit_id' => ['nullable', 'integer', 'exists:units,id'],
  22. ];
  23. }
  24. }