Edit File: RegisterRequest.php
<?php namespace App\Http\Requests\DelegatesDashboard; use Illuminate\Foundation\Http\FormRequest; use App\Traits\Responses; use Illuminate\Contracts\Validation\Validator; use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Http\Request; use App\Traits\ApiTrait; use App\Traits\GeneralTrait; use App\Models\User; use App; class RegisterRequest extends FormRequest { use ApiTrait,GeneralTrait; /** * 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() { return[ 'avatar' => 'required|image', 'name' => 'required|string|min:3|max:191', 'phone' => ['required','min:9','max:11', 'unique:users,phone'], 'email' => ['nullable', 'email', 'unique:users,email'], 'city_id' => 'required', 'country_key' => 'required', 'commercial_number' =>'required|numeric|digits_between:10,15', 'commercial_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg', 'bank_account_number' =>'required|digits_between:16,25', 'password' => 'required|confirmed|min:8', 'password_confirmation' => 'required|same:password', 'terms' => 'accepted', 'type' => 'nullable', 'approve'=>'nullable', ]; } protected function prepareForValidation() { $number = $this->convert2english($this->phone); $phone = $this->phoneValidate($number); $this->merge([ 'phone' => $phone , 'type'=>'company', 'approve'=>'pending', ]); } protected function failedValidation( \Illuminate\Contracts\Validation\Validator $validator) { $msg = implode(' , ',$validator->errors()->all()); throw new HttpResponseException(response()->json(['key'=>'fail','msg'=>$msg])); } }
Back to File Manager