user(); return $user->can('create', BankTransactionRule::class) && $user->account->hasFeature(Account::FEATURE_API); ; } public function rules() { /** @var \App\Models\User $user */ $user = auth()->user(); /* Ensure we have a client name, and that all emails are unique*/ $rules = [ 'name' => 'bail|required|string', 'rules' => 'bail|array', 'rules.*.operator' => 'bail|required|nullable', 'rules.*.search_key' => 'bail|required|nullable', 'rules.*.value' => 'bail|required|nullable', 'auto_convert' => 'bail|sometimes|bool', 'matches_on_all' => 'bail|sometimes|bool', 'applies_to' => 'bail|sometimes|string', ]; $rules['category_id'] = 'bail|sometimes|exists:expense_categories,id,company_id,'.$user->company()->id.',is_deleted,0'; $rules['vendor_id'] = 'bail|sometimes|exists:vendors,id,company_id,'.$user->company()->id.',is_deleted,0'; $rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.$user->company()->id.',is_deleted,0'; return $rules; } public function prepareForValidation() { $input = $this->all(); $input = $this->decodePrimaryKeys($input); $this->replace($input); } }