user()->can('edit', $this->vendor); } public function rules() { /* Ensure we have a client name, and that all emails are unique*/ $rules['country_id'] = 'integer|nullable'; if ($this->number) { $rules['number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id)->ignore($this->vendor->id); } // if($this->id_number) // $rules['id_number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id)->ignore($this->vendor->id); $rules['contacts.*.email'] = 'nullable|distinct'; // $rules['id_number'] = 'unique:vendors,id_number,'.$this->id.',id,company_id,'.auth()->user()->company()->id; return $rules; } public function messages() { return [ 'email' => ctrans('validation.email', ['attribute' => 'email']), 'name.required' => ctrans('validation.required', ['attribute' => 'name']), 'required' => ctrans('validation.required', ['attribute' => 'email']), ]; } public function prepareForValidation() { $input = $this->all(); if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) { $input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']); } $input = $this->decodePrimaryKeys($input); $this->replace($input); } }