user(); return $user->can('create', Vendor::class); } public function rules() { /** @var \App\User|null $user */ $user = auth()->user(); $rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email'; if (isset($this->number)) $rules['number'] = Rule::unique('vendors')->where('company_id', $user->company()->id); $rules['currency_id'] = 'bail|required|exists:currencies,id'; return $rules; } public function prepareForValidation() { /** @var \App\User|null $user */ $user = auth()->user(); $input = $this->all(); if(!array_key_exists('currency_id', $input) || empty($input['currency_id'])){ $input['currency_id'] = $user->company()->settings->currency_id; } $input = $this->decodePrimaryKeys($input); $this->replace($input); } public function messages() { return [ 'contacts.*.email.required' => ctrans('validation.email', ['attribute' => 'email']), ]; } }