user()->can('edit', $this->bank_transaction); } public function rules() { /* Ensure we have a client name, and that all emails are unique*/ $rules = [ 'date' => 'bail|required|date', 'description', 'bail|required|string' ]; if (isset($this->currency_id)) $rules['currency_id'] = 'sometimes|exists:currencies,id'; if(isset($this->vendor_id)) $rules['vendor_id'] = 'bail|required|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; if(isset($this->expense_id)) $rules['expense_id'] = 'bail|required|exists:expenses,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; return $rules; } public function prepareForValidation() { $input = $this->all(); if(array_key_exists('vendor_id', $input) && strlen($input['vendor_id']) > 1) $input['vendor_id'] = $this->decodePrimaryKey($input['vendor_id']); if(array_key_exists('expense_id', $input) && strlen($input['expense_id']) > 1) $input['expense_id'] = $this->decodePrimaryKey($input['expense_id']); if(array_key_exists('ninja_category_id', $input) && strlen($input['ninja_category_id']) > 1) $input['ninja_category_id'] = $this->decodePrimaryKey($input['ninja_category_id']); $this->replace($input); } }