Edit File: UpdateRequest.php
<?php namespace App\Http\Requests\Admin\Provider; use App\Models\Provider; 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()); $id = $this->id; $provider = Provider::with('bankAccount')->find($id); // get bank account id $bankAccountId = $provider->bankAccount?->id; return [ // General Information for Auth 'image' => 'nullable|image|mimes:jpeg,png,jpg,svg,webp|max:2048', 'logo' => 'nullable|image|mimes:jpeg,png,jpg,svg,webp|max:2048', 'name' => 'required|string|max:200', // Store Information 'identity_number' => ['required', 'numeric', 'digits_between:10,16', Rule::unique('providers', 'identity_number')->whereNull('deleted_at')->ignore($id)], 'civil_registration_number' => ['required', 'numeric', 'digits_between:10,16', Rule::unique('providers', 'civil_registration_number')->whereNull('deleted_at')->ignore($id)], 'tax_number' => ['required', 'numeric', 'digits_between:10,16', Rule::unique('providers', 'tax_number')->whereNull('deleted_at')->ignore($id)], 'store_name' => 'required|array', 'store_name.*' => 'required|max:200', 'store_description' => 'required|array', 'store_description.*' => 'required|max:500', 'country_code' => 'required|numeric|digits_between:2,5', 'phone' => [ 'required', 'numeric', 'digits_between:9,10', Rule::unique('providers', 'phone') ->whereNull('deleted_at')->ignore($id) ], 'email' => [ 'nullable', 'email:rfc,dns', 'max:100', Rule::unique('providers', 'email')->whereNull('deleted_at')->ignore($id) ], 'whatsapp_country_code' => 'required|numeric|digits_between:2,5', 'whatsapp_phone' => [ 'required', 'numeric', 'digits_between:9,10', Rule::unique('providers', 'whatsapp_phone') ->whereNull('deleted_at')->ignore($id) ], 'category_id' => [ 'required', 'numeric', Rule::exists('categories', 'id')->whereNull('parent_id') ], 'sub_categories' => 'required|array', 'sub_categories.*' => [ 'required', 'numeric', 'exists:categories,id', Rule::exists('categories', 'id') ->whereNotNull('parent_id')->where('parent_id', (int) $this->category_id) ], // Location Information 'city_id' => 'required|numeric|exists:cities,id', 'neighborhood_id' => 'required|numeric|exists:neighborhoods,id', // 'lat' => 'required|numeric', // 'lng' => 'required|numeric', // 'map_desc' => 'nullable|string|max:255', // bank account 'minimum_order' => 'required|numeric|min:1|max:100000', 'bank_name' => 'required|string|max:255', 'account_name' => 'required|string|max:255', 'account_number' => [ 'required', 'numeric', Rule::unique('bank_accounts', 'account_number') ->whereNull('deleted_at')->ignore($bankAccountId), 'digits_between:10,20' ], 'iban' => [ 'required', 'string', 'regex:/(SA)[0-9]{22}/', Rule::unique('bank_accounts', 'iban') ->whereNull('deleted_at')->ignore($bankAccountId), ], 'bank_account_image' => 'nullable|file|mimes:jpeg,png,jpg,pdf|max:2048', // end bank account ]; } public function prepareForValidation(): void { $this->merge([ 'phone' => fixPhone($this->phone), 'country_code' => fixPhone($this->country_code), 'whatsapp_phone' => fixPhone($this->whatsapp_phone), 'whatsapp_country_code' => fixPhone($this->whatsapp_country_code), ]); } }
Back to File Manager