json(); } /** * Prepare the data for validation. */ protected function prepareForValidation(): void { $codesAvailableToExport = Code::query()->where('code_exported', false); /** @var int|null $lastExportedId */ $lastExportedId = Code::query()->where('code_exported', true)->max('id'); if ($lastExportedId) { $codesAvailableToExport->where('id', '>', $lastExportedId); } $this->merge([ 'available_export' => $codesAvailableToExport->count(), ]); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { return [ 'nb_code_tot' => 'required|integer|min:1|lte:available_export', 'nb_code_fic' => 'required|integer|min:1', 'nb_code_ligne' => 'required|integer|min:1', 'available_export' => 'required|integer', ]; } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'nb_code_fic' => trans('nombre total de codes à exporter'), 'nb_code_tot' => trans('nombre de codes par fichier'), 'nb_code_ligne' => trans('nombre de codes par ligne'), 'available_export' => trans('nombre de codes restant à exporté(s)'), ]; } }