Edit File: UpdateRequest.php
<?php namespace App\Http\Requests\Admin\Delegate; use App\Models\Delegate; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; class UpdateRequest extends FormRequest { /** * 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() { // dd($this->all()); define('VALIDATE_SIZE', 'nullable|array|size:2'); define('VALIDATE_IMAGE', 'nullable|image|mimes:jpeg,png,jpg,gif,webp|max:2048'); $delegate = Delegate::with('bankAccount')->find($this->id); $bankAccountId = $delegate->bankAccount?->id; return [ 'name' => 'required|max:50', 'image' => VALIDATE_IMAGE, 'country_code' => 'required|numeric|digits_between:2,5', 'phone' => 'required|numeric|digits_between:9,10|unique:delegates,phone,' . $this->id . ',id,deleted_at,NULL', 'email' => 'nullable|email:rfc,dns|unique:delegates,email,' . $this->id . ',id,deleted_at,NULL|max:50', 'lat' => 'required|numeric', 'lng' => 'nullable|numeric', 'map_desc' => 'required|string', 'city_id' => 'required|exists:cities,id', 'car_plat_number' => 'required|string|max:50', 'is_approved' => 'nullable', // 'car_images' => VALIDATE_SIZE, 'car_images.*' => VALIDATE_IMAGE, // 'identity_images' => VALIDATE_SIZE, 'identity_images.*' => VALIDATE_IMAGE, // 'licencses_certificate' => VALIDATE_SIZE, 'licencses_certificate.*' => VALIDATE_IMAGE, 'neighborhoods' => 'required|array', 'neighborhoods.*' => 'required|numeric|exists:neighborhoods,id', // bank account 'bank_name' => 'required|string|max:255', 'account_name' => 'required|string|max:255', 'account_number' => [ 'required', 'numeric', 'digits_between:10,20', Rule::unique('bank_accounts', 'account_number')->ignore($bankAccountId)->whereNull('deleted_at'), ], 'iban' => [ 'required', 'string', 'regex:/(SA)[0-9]{22}/', Rule::unique('bank_accounts', 'iban')->ignore($bankAccountId)->whereNull('deleted_at'), ], // end bank account ]; } public function prepareForValidation() { $this->merge([ 'phone' => fixPhone($this->phone), 'country_code' => fixPhone($this->country_code), 'is_approved' => 1, ]); } public function messages() { return [ 'lat.required' => __('admin.must_enter_valid_location'), 'lat.numeric' => __('admin.must_enter_valid_location'), 'map_desc.required' => __('admin.must_enter_valid_location'), ]; } }
Back to File Manager