File: /mnt/data/ghayatcom/ghayatcom-api/app/Http/Requests/SubmitConsultationRequest.php
<?php
namespace App\Http\Requests;
use App\Library\CustomFailedValidation;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\Rule;
class SubmitConsultationRequest extends CustomFailedValidation
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$data = $this->request->all();
$rules = [];
if($this->status == 1) {
$rules['appointment_id'] = 'required|exists:appointments,id';
$rules['health_record'] = 'required';
$health_record = json_decode($data['health_record']);
/**
* @var object $health_record
*/
$rules['diagnosis'] = Rule::requiredIf(function() use ($health_record) {
return (empty($health_record->diagnosis)) ? true : false;
});
$rules['treatment_given'] = Rule::requiredIf(function() use ($health_record) {
return (empty($health_record->treatment_given)) ? true : false;
});
$rules['referal'] = 'required';
$referal = json_decode($data['referal']);
/**
* @var object $referal
*/
$rules['presenting_complaints'] = Rule::requiredIf(function() use ($referal) {
if($referal->is_referal == 1){
return (empty($referal->presenting_complaints)) ? true : false;
}
else {
return false;
}
});
if($this->hasFile('patient_certificate')){
$rules['patient_certificate'] = 'mimes:jpg,jpeg,png,pdf';
}
if($this->hasFile('employer_certificate')){
$rules['patient_certificate'] = 'mimes:jpg,jpeg,png,pdf';
}
}
return $rules;
}
public function messages()
{
return [
'appointment_id.required' => __('digimed_validation.form_validation_error.appointment_id_req'),
'appointment_id.exists' => __('digimed_validation.form_validation_error.appointment_id_is_not_exisit')
];
}
}